Reputation:
I'm setting up a python bot for my discord server. I'm trying to add a feature that when people join they type - and the bot will assign them to the role stated
I have tried to assign the role I want by using message.roles and server.roles but both still feed off the same error.
BOT_PREFIX = ('-')
...
#ComputerScience
@client.command(pass_context = True)
async def Cs(member, *roles):
role = discord.utils.get(server.roles, name="ComputerScience")
await client.add_role(member, role)
When '-Cs' is typed in chat it shows give them the computer science role but instead I get: "Ignoring exception in command Cs ... NameError: name 'server' is not defined"
Upvotes: 0
Views: 3454
Reputation: 60974
You're passing the invocation context, but not accepting it in the function signature of your command. That context is where you can get the server
from:
@client.command(pass_context = True)
async def Cs(ctx):
role = discord.utils.get(ctx.message.server.roles, name="ComputerScience")
await client.add_role(ctx.message.author, role)
Upvotes: 1