I want to create a Discord bot command.
For example, I would like to create a warning command. So the admin would enter the following command:
?Warn @user "<A warning message>"
The command will then check if the targeted user (@user
) has certain roles (for example, "A", "B", "C" and "D"). If he doesn't have the "A" role he will get it, if he has A, he gets B and so on.
The admin must have the "Staff Team" role to use the command.
I tried this but it didn't work:
#Warning
@bot.command(name="Warn", pass_context=True)
@commands.has_role("Staff Team")
async def addrole(ctx,arg):
user = arg
if user.role.name != "Warning 1" or "Warning 2" or "Warning 3":
role = get(user.server.roles, name="Warning 1")
await bot.add_roles(user, role)
elif user.role.name == "Warning 1":
role = get(user.server.roles, name="Warning 2")
role_last = get(user.server.roles, name="Warning 1")
await bot.add_roles(user, role)
await bot.remove_roles(user,role_last)
elif user.role.name == "Warning 2":
role = get(user.server.roles, name="Warning 3")
role_last = get(user.server.roles, name="Warning 2")
await bot.add_roles(user, role)
await bot.remove_roles(user,role_last)
Then the bot DMs the user with text and then the message.
role_object in user.roles
– chluebi