Reputation:
I am trying to make a discord bot that creates a role when someone sends a message. For some reason, It keeps saying 'ctx' is not defined. How would I fix this error?
@client.event
async def on_message(message):
server=ctx.message.server
perms=discord.Permissions(administrator=true)
await client.create_role(server,name='testrole', colour=discord.Colour(0x0000FF),permissions=perms)
when i change
async def on_message(message):
to
async def on_message(ctx):
it says 'message' is not defined. I do not understand how I could define both of these because when I add the undefined part as shown below, It still says 'ctx' is not defined or 'message' is not defined.
async def on_message(message,ctx):
async def on_message(ctx,message):
update: I didn't have (pass_context=True) but now I know more
Upvotes: 1
Views: 256
Reputation:
Try this:
@client.event
async def on_message(message):
guild=message.guild
perms=discord.Permissions(administrator=True)
await guild.create_role(name='testrole', colour=discord.Colour(0x0000FF),permissions=perms)
P.S. your bot need some permissions to create this Role.
Upvotes: 1