intents = discord.Intents.all() intents.members = True bot = commands.Bot(command_prefix='G!',intents = intents) for filename in os.listdir('./cmds'): #寫入cmds裡的.py if filename.endswith('.py'): bot.load_extension(f'cmds.{filename[:-3]}') @bot.command() async def load(ctx, extension): bot.load_extension(f'cmds.{extension}') await ctx.send(f'{extension} has loaded!') @bot.command() async def unload(ctx, extension): bot.unload_extension(f'cmds.{extension}') await ctx.send(f'{extension} has unloaded!') @bot.command() async def reload(ctx, extension): bot.reload_extension(f'cmds.{extension}') await ctx.send(f'{extension} has reloaded!') @bot.event async def on_ready(): print(f'{jdata["Name"]} is online.') if __name__ == "__main__": bot.run(jdata['TOKEN'])

寫在主程式裡的指令都能正常執行
但如果把指令搬到其他子class裡的話就會找不到指令

from discord.ext import commands
import discord
class Main(commands.Cog):
    def __init__ (self,bot):
        self.bot = bot
    @commands.command()
    async def say(self,ctx):
        await ctx.send('hello')
def setup(bot):
    bot.add_cog(Main(bot))

爬文爬了老半天,看了官方的API也沒有頭緒
測試了很久也不知道是哪邊出錯了
所以來這裡尋求大家協助
第一次發文,如果有說明不清楚的地方再麻煩指教了~

IDE:VScode
Python版本:3.8.9

謝謝大家撥冗時間看完這篇文QQ