import discord
from discord.utils import get
client = discord.Client()
@client.event
async def on_message(message):
if message.author == client.user:
return
if 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)
async def addrole(ctx, role: discord.Role, member: discord.Member=None):
member = member or ctx.message.author
await client.add_roles(member, role)
bot.run("token")
@
in front ofasync
shouldn't be there. This function should be decorated with@client.event
, or something similar. Instead ofmessage.author.id
, just passmessage.author
toadd_roles
message.server.roles
.