Discord.py how do I make a mute command?

孤者浪人 提交于 2021-01-06 07:52:56

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!