【问题标题】:discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'id'discord.ext.commands.errors.CommandInvokeError:命令引发异常:AttributeError:'NoneType'对象没有属性'id'
【发布时间】:2020-10-10 10:09:11
【问题描述】:

我制作了我的不和谐机器人,并发出静音命令

@bot.command(pass_context = True)
@commands.has_any_role('Тестеры',764167672971657236)
async def мут(ctx, member: discord.Member):
    role = discord.utils.get(member.guild.roles, name="muted")
    await member.add_roles(role, member) 
    embed=discord.Embed(title="Пользователь получил бан чата!", description="**{0}**  получил бан чата от **{1}**! За размутом обращайтесь к администратору!".format(member, ctx.message.author), color=0xff00f6)
    await ctx.send(embed=embed)

它的工作,但重新启动电脑后我得到错误

Traceback (most recent call last):
  File "C:\Users\Ivan\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\bot.py", line 903, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\Ivan\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 859, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\Ivan\AppData\Local\Programs\Python\Python38-32\lib\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: AttributeError: 'NoneType' object has no attribute 'id'

请帮忙

【问题讨论】:

  • id 没有任何关系。你确定这段代码有问题吗?

标签: python discord.py


【解决方案1】:

机器人无法获得名称为“静音”的角色,而且这不是您赋予角色的方式。

以下是修改后的代码:

@bot.command(pass_context = True)
@commands.has_any_role('Тестеры',764167672971657236)
async def мут(ctx, member: discord.Member):
    role = discord.utils.get(member.guild.roles, name="muted") # make sure role is named muted and not Muted
    await member.add_roles(role) 
    embed=discord.Embed(title="Пользователь получил бан чата!", description="**{0}**  получил бан чата от **{1}**! За размутом обращайтесь к администратору!".format(member, ctx.message.author), color=0xff00f6)
    await ctx.send(embed=embed)

【讨论】:

    猜你喜欢
    • 2022-01-25
    • 2021-02-05
    • 2021-01-30
    • 2021-12-07
    • 1970-01-01
    • 2022-01-05
    • 1970-01-01
    • 1970-01-01
    • 2021-12-04
    相关资源
    最近更新 更多