Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

All relevant discord connections have been made, and the bot recognizes mute and unmute as a command, it just doesnt work. Also - how can i make it so there is a time for the mute?

@client.command()
async def mute(ctx, member: discord.Member):
role_members = discord.utils.get(ctx.guild.roles, name='Member')
role_muted = discord.utils.get(ctx.guild.roles, name='Muted')
await member.remove_roles(role_members)
await member.add_roles(role_muted)
await context.send("f'User {member} Was Muted")

@client.command()
async def unmute(ctx, member: discord.Member):
role_members = discord.utils.get(ctx.guild.roles, name='Member')
role_muted = discord.utils.get(ctx.guild.roles, name='Muted')
await member.remove_roles(role_muted)
await member.add_roles(role_members)
await context.send("f'User {member} Was Unmuted")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
4.1k views
Welcome To Ask or Share your Answers For Others

1 Answer

This should work. I took this from another stack overflow post. This code will find the user and add them to the "muted" server role.

@bot.command(pass_context = True)
async def mute(ctx, member: discord.Member):
     if ctx.message.author.server_permissions.administrator or ctx.message.author.id == '194151340090327041':
        role = discord.utils.get(member.server.roles, name='Muted')
        await bot.add_roles(member, role)
        embed=discord.Embed(title="User Muted!", description="**{0}** was muted by **{1}**!".format(member, ctx.message.author), color=0xff00f6)
        await bot.say(embed=embed)
     else:
        embed=discord.Embed(title="Permission Denied.", description="You don't have permission to use this command.", color=0xff00f6)
        await bot.say(embed=embed)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...