Discord.py齿轮可以在Windows上使用,但不能在Archlinux中使用

时间:2020-07-21 14:34:37

标签: discord.py discord.py-rewrite

所以我的问题很简单,但仍然很烦人。一段时间以来,我写了一个机器人,并在Windows 10上对其进行了调试,直到我尝试在其他OS(Archlinux)上运行它,一切似乎都可以正常工作。

开始时,它运行良好,当我在另一个StackOverflow问题上阅读时,我使用dos2unix删除了Windows结尾。当文件启动时,我定义的 init 东西会按我的意愿执行,并显示我的打印内容,但是当我尝试例如在齿轮中定义的on_message时,它根本无法工作。什么也没显示,我也没有回应。我尝试了其他功能,例如on_member_join,但是也没有用。

因此,基本上,从一开始就只在discord.py cog文件中执行 init 代码,但是它不想执行在该文件中也定义的任何命令或事件。

那么,有谁知道这件事或对我有帮助的事吗?

如果这有助于解决on_message中的cog文件代码:

import sys, traceback
from discord.ext import tasks, commands
import datetime
from datetime import date
import discord
import asyncio

def ctime():
    global date_now
    date_now = date.today
    global now
    now = datetime.now()
    current_time = now.strftime("%Y-%m-%d %H:%M:%S")
    return current_time

class On_Message(commands.Cog):
    def __init__(self, client):
        self.client = client
        current_time = ctime()
        print(f"{current_time} EXTENSION ON_MESSAGE RESPONDED") 

    @commands.Cog.listener()
    async def on_message(self, message):
        try:
            **stuff**
   


def setup(client):
    client.add_cog(On_Message(client))

编辑:添加了main.py文件:

import discord
from discord.ext import commands
from discord.utils import get
import asyncio
from datetime import datetime
from datetime import date
from typing import Optional
from discord.ext.commands import Bot
import sys, traceback
import os
from discord.ext import tasks, commands

import FoxBot.cogs.background
import FoxBot.cogs.cogs
import FoxBot.cogs.database
import FoxBot.cogs.members
import FoxBot.cogs.on_message
import FoxBot.cogs.on_raw_reaction_add
import FoxBot.cogs.setup
import FoxBot.cogs.startup

def ctime():
    global date_now
    date_now = date.today
    global now
    now = datetime.now()
    current_time = now.strftime("%Y-%m-%d %H:%M:%S")
    return current_time

try:
    TOKEN = 'DISCORD_TOKEN'
    command_prefix = "."
    client = commands.Bot(command_prefix = command_prefix, description='A bot')

    initial_extensions = ['members.py',
                        'cogs.py',
                        'on_message.py',
                        'startup.py',
                        'background.py',
                        'setup.py',
                        'database.py',
                        'on_raw_reaction_add.py'] # List of files to import as cogs
except Exception as e:
    ...

for filename in os.listdir('Bot/cogs'):
    current_time = ctime()
    if filename == "__init__.py":
        break
    elif filename.endswith('.py') and filename in initial_extensions:
        client.load_extension(f'FoxBot.cogs.{filename[:-3]}')
        print(f"{current_time} EXTENSION {filename} LOADED!")   

@client.event
async def on_ready():
    try:
        **startup-stuff that has no relation to the cogs like discord.Activity etc. and prints**  
    except Exception as e:
        ...


0 个答案:

没有答案