Skip to content Skip to sidebar Skip to footer

How To Make A Discord Bot That Gives Roles In Python?

I want to create a discord bot that gives roles to members in Python. I tried this: @async def on_message(message): if message.content == 'give me admin' role = dis

Solution 1:

import discord
from discord.utils import get

client = discord.Client()

@client.eventasyncdefon_message(message):
    if message.author == client.user:
        returnif message.content == 'give me admin':
        role = get(message.server.roles, name='Admin')
        await client.add_roles(message.author, role)

I think this should work. The documentation for is here.

You could also use the discord.ext.commands extension:

from discord.ext.commands import Bot
import discord

bot = Bot(command_prefix='!')

@bot.command(pass_context=True)asyncdefaddrole(ctx, role: discord.Role, member: discord.Member=None):
    member = member or ctx.message.author
    await client.add_roles(member, role)

bot.run("token")

Solution 2:

All you need to do is

import discord
from discord.utils import get

@client.eventasyncdefon_message(message):
    if message.content == "give me admin":
        member = message.author
        role = get(member.guild.roles, name="Admin")
        await member.add_roles(role)

Post a Comment for "How To Make A Discord Bot That Gives Roles In Python?"