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 discord.py 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")
Post a Comment for "How To Make A Discord Bot That Gives Roles In Python?"