问题
As the title says. I'm trying to figure out how to make a mute command using discord.py rewrite. I'm thinking that we need to have a "mute" role where the command used gives the user the "mute" role and for how long. How do I achieve this.
I already have
@bot.command()
@commands.has_permissions(mute_members)
async def mute(ctx, member:discord.Member):
回答1:
The best way to do this would be to have a database setup in which you can add and remove users. Then you can use the on_message
event and check if the author is in the database, if it is then delete the message. You could also just use a list/file for it to be simpler.
回答2:
you can create a Muted role and make your bot add the role to the user you want to mute:
@bot.command()
async def mute(ctx, member: discord.Member):
role = discord.utils.get(ctx.guild.roles, name='Muted')
await member.add_roles(role)
await ctx.send("role added")
来源:https://stackoverflow.com/questions/47974280/discord-py-how-do-i-make-a-mute-command