简体   繁体   中英

Discord.py mute command allows people to send messages

I have been implementing a mute command into my discord bot and I have a problem. When I do $mute , it still allows them to send messages because the @everyone role has the permission to send messages. Taking away the "Send Messages" permission from @everyone fixes it, but I was wondering if there was a way to make it so that when the user has the @Muted role, the permissions for @everyone will be overwritten. Here is the code:

@client.command()
@commands.has_permissions(kick_members = True)
async def mute(ctx, member : discord.Member):
    guild = ctx.guild
    role = discord.utils.get(guild.roles, name="Muted")

    if role not in guild.roles:
        perms = discord.Permissions(send_messages=False, speak=False)
        await guild.create_role(name="Muted", permissions=perms)
        await member.edit(roles=role)
        await ctx.send(f"{member.name} was muted.")
    else:
        await member.edit(roles=role)
        await ctx.send(f"{member} was muted.")

I'm sorry if it's a bit hard to understand.

I have been implementing a mute command into my discord bot and I have a problem. When I do $mute , it still allows them to send messages because the @everyone role has the permission to send messages. Taking away the "Send Messages" permission from @everyone fixes it, but I was wondering if there was a way to make it so that when the user has the @Muted role, the permissions for @everyone will be overwritten. Here is the code:

@client.command()
@commands.has_permissions(kick_members = True)
async def mute(ctx, member : discord.Member):
    guild = ctx.guild
    role = discord.utils.get(guild.roles, name="Muted")

    if role not in guild.roles:
        perms = discord.Permissions(send_messages=False, speak=False)
        await guild.create_role(name="Muted", permissions=perms)
        await member.edit(roles=role)
        await ctx.send(f"{member.name} was muted.")
    else:
        await member.edit(roles=role)
        await ctx.send(f"{member} was muted.")

I'm sorry if it's a bit hard to understand.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM