【问题标题】:Ignoring exception in command None: discord.ext.commands.errors.CommandNotFound: Command "memechannel" is not found error (discord.py)忽略命令无异常:discord.ext.commands.errors.CommandNotFound:找不到命令“memechannel”错误(discord.py)
【发布时间】:2021-02-19 15:26:33
【问题描述】:

好的,所以我制作了一个 Discord Bot,它从 reddit 获取模因并每 5 分钟将其发送到用户指定的频道,为此我必须创建一个 cog

#imports
import discord
...
...
#Automemer
class Automemer(commands.Cog):
    def __init__(self, client):
....

#used to loop the task of posting memes
    @tasks.loop(minutes=5.0)
    async def automemer(self):
        all_subs = []
...
#start of formating embed for task loop
            name = random_sub.title
            url = random_sub.url
            em = discord.Embed(title = name)
            em.set_image(url = url)
            em.color = 0xff0000
em.set_footer(text=f'Memes from r/AmongUsMemes')
            #used to post the memes where the user does the command am.memechannel
            @commands.command()
            async def memechannel(self, ctx):
                channel_id = ctx.channel.id
                await ctx.send('Memes will now be sent in this channel')
                memeChannel = ctx.guild.get_channel(channel_id)
                if memeChannel:
                    emoji1 = ':arrow_up:'
                    emoji2 = ':arrow_down:'
                    msg = await ctx.send(embed=em)
                    await msg.add_reaction(emoji1)
                    await msg.add_reaction(emoji2)
                    await ctx.send(embed=em)

Error = Ignoring exception in command None: discord.ext.commands.errors.CommandNotFound: Command "memechannel" is not found

每当我运行命令 am.memechannel 时都会发生错误。

如果有人告诉我如何解决这个错误,那就太好了。 这是该机器人的最后一个功能,这将是我第一个向公众发布的 Discord Bot! :)

【问题讨论】:

    标签: python python-3.x discord bots discord.py


    【解决方案1】:

    你在任务循环中定义了命令,你的缩进搞砸了。你应该把命令放在循环下面,而不是放在里面。

    @tasks.loop(minutes=5.0)
    ...
    
    @commands.command()
    ...
    

    请记住,您的 em 变量仅在您的任务中可见,因此您必须找到解决此问题的方法,否则您无法在命令中使用它。一个例子是将其添加为类变量。

    def __init__(self, client):
        self.em = discord.Embed()
    

    然后在你继续的过程中覆盖那个变量。

    self.em = discord.Embed(title=name)
    ...
    

    【讨论】:

      猜你喜欢
      • 2021-02-06
      • 2023-02-25
      • 2021-09-12
      • 2021-06-06
      • 2019-03-24
      • 2021-11-11
      • 2021-11-14
      • 2018-06-20
      • 1970-01-01
      相关资源
      最近更新 更多