enderelijas
enderelijas

Reputation: 27

How do you use permission overwrites? Discord.py Rewrite

I have been trying to make a mute command and a ticket command for my discord bot but i can't wrap my head around permission overwrites. Thank you in advance

Upvotes: 1

Views: 8808

Answers (1)

Diggy.
Diggy.

Reputation: 6944

Here's a command for editing a certain member's permissions server-wide (i.e. for each text channel the bot can see):

Example

import discord # if you get an error about discord not being defined, include this at the top

@bot.command()
async def mute(ctx, member: discord.Member):
    for channel in ctx.guild.text_channels:
        perms = channel.overwrites_for(member)
        perms.send_messages = False
        await channel.set_permissions(member, overwrite=perms, reason="Muted!")
    await ctx.send(f"{member} has been muted.")

References:

Upvotes: 4

Related Questions