【问题标题】:Cogs Not Working and not detected In Discord.py齿轮不工作且未在 Discord.py 中检测到
【发布时间】:2023-01-26 05:17:38
【问题描述】:

我的机器人程序无法检测到 cogs 文件 我已经尝试了各种方法来解决它,但仍然没有任何改变

主程序

import discord
import os


from discord.ext import commands


intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix='$', intents=intents)

async def load():
    for filename in os.listdir('./cogs'):
        if filename.endswith('.py'):
            await bot.load_extension(f'cogs.{filename[:-3]}')

            
bot.run('MTA2NzQ1MDMxMTAzMzIzMzUxOA.GSdg-i.CW3X5T82VYGYjPqEPWZ8YQ6oDZni33T-Bi1Ovo')

实验室.py

import discord
from discord.ext import commands

class lab(commands.Cog):

    def __init__(self,bot):
        self.bot = bot


    @commands.Cog.listener()
    async def on_ready(self):
        print('lab.py is running')
    
    @commands.command()
    async def holla(ctx):
       await ctx.reply('hai')


async def setup(bot):
    await bot.add_cog(lab(bot))

eror

我需要有人帮我解决我的问题,在此先感谢

【问题讨论】:

  • 不要在互联网上共享您的令牌。请考虑在不和谐的开发者门户中重新生成一个

标签: discord.py discogs-api


【解决方案1】:

你从不呼唤那个 load() 函数...你制作它很酷,但如果你不使用它,那么你的齿轮没有被加载也就不足为奇了。

推荐的这样做的地方是setup_hook。子类 Client(或 Bot 取决于你想要什么)并覆盖它。

【讨论】:

    猜你喜欢
    • 2021-04-12
    • 2022-01-05
    • 1970-01-01
    • 1970-01-01
    • 2020-10-10
    • 2020-04-14
    • 2023-03-14
    • 2012-03-31
    • 2023-04-03
    相关资源
    最近更新 更多