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")
))
I was trying to recreate the role of mute. Change interaction.guild.roles to interaction.message.guild.roles
ID's are ints, not strings. You're passing a string to
utils.get, so nothing is found andmute_roleisNone, as your error message is telling you.Pass the ID as an int instead.
Docs for
Role.id: https://discordpy.readthedocs.io/en/stable/api.html#discord.Role.id