【问题标题】:TempMute | NotFound: 404 Not Found (error code: 10011): Unknown Role静音 | NotFound:404 Not Found(错误代码:10011):未知角色
【发布时间】:2022-01-07 12:35:07
【问题描述】:

我正在尝试执行“tempmute”命令之类的操作,但不断弹出错误 :

Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 939, in invoke
    await ctx.command.invoke(ctx)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 863, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: NotFound: 404 Not Found (error code: 10011): Unknown Role

这是命令代码

@commands.command()
    @commands.has_permissions(ban_members=True)
    async def tempmute(self, ctx, member: discord.Member = None, * time):
        if not member:
            await ctx.send(embed=discord.Embed(title='Вы должны указать участника!', color=random.choice(colors)))
        else:
            LMUTED = discord.utils.get(ctx.message.guild.roles, name='LMUTED')
            if not LMUTED:
                perms=discord.Permissions(send_messages=False)
                await ctx.guild.create_role(name='LMUTED', 
                colour=discord.Colour(0x0000FF),
                permissions = perms)
                await ctx.send(f'Я создал роль `{LMUTED}`!')
            await member.add_roles(member, LMUTED)
            await ctx.send(f'Я замьютил {member} на {time}!')
            await s(time * 60)
            await ctx.remove_roles(member, LMUTED)

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    确保你知道how to read python errors

    但是这里的主要问题是您在创建新角色后没有为LMUTED赋值,所以它仍然是None,因此discord.py无法添加角色。

    另外,请记住,当你做的事情随着时间的推移而过期时,简单地在方法中休眠/等待并不是处理它的好方法,因为线程可能被锁定。相反,您应该使用某种scheduler。基本上是在运行一些代码之前等待一定时间的东西。

    【讨论】:

      猜你喜欢
      • 2021-03-08
      • 2017-11-03
      • 2017-04-09
      • 1970-01-01
      • 2019-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-18
      相关资源
      最近更新 更多