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.
This is anwser:
async def Warn(ctx, args1: discord.Member, args2 = "no reason"):
^ ^
User Mention Optional
Member = args1
Role = ctx.guild.get_role(ROLE ID)
for roles in Member.roles:
if roles != Role: or if roles == Role:
await Member.add_roles(Role)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With