I wanted to write a mute command for a bot in the discord

44 Views Asked by At

I wanted to write a mute command for a bot in the discord. The command does not work. Here's the code and the error

@bot.tree.command(name="mute", description="Мьют участника")
@app_commands.checks.has_permissions( administrator = True )
async def mute( interaction: discord.Interaction, member: discord.Member,reason: str = None ):
    await interaction.response.defer( thinking = True )
    await interaction.channel.purge( limit = 1 )
    mute_role = discord.utils.get (  interaction.guild.roles, id = '1061014280922746887', name = 'muted' )
    await member.add_roles( mute_role )
    await interaction.channel.send( embed = discord.Embed(    
    title="Участник успешно замьючен",
    description= ( f"{member.mention} **был замьючен модератором** {interaction.user.mention}! "), 
    color=discord.Color.from_str("#C3F")
    ))

error

I was trying to recreate the role of mute. Change interaction.guild.roles to interaction.message.guild.roles

1

There are 1 best solutions below

0
stijndcl On

ID's are ints, not strings. You're passing a string to utils.get, so nothing is found and mute_role is None, as your error message is telling you.

discord.utils.get(interaction.guild.roles,id='1061014280922746887',name='muted')
#                                            ^^^^^^^^^^^^^^^^^^^^^ string

Pass the ID as an int instead.

Docs for Role.id: https://discordpy.readthedocs.io/en/stable/api.html#discord.Role.id

Type: int