Reputation: 21
I make my discord bot, and make the mute command
@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)
and its working, but after restarting pc i got error
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'
Please help
Upvotes: 2
Views: 4351
Reputation: 4225
The bot can't get the role with the name "muted" and also that's not how you give roles.
Below is the revised code:
@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)
Upvotes: 1