2

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

1
  • There's nothing related to id. Are you sure this code is causing problem? Commented Oct 10, 2020 at 10:18

1 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.