Reputation: 26
I'm new to creating bots on discord and can't figure out how I can add a role to multiple users simply by writing a chat message. I have tried to search various methods on the internet but all I add the role to the author of the message while I need it to add the role to specific users
Upvotes: 0
Views: 254
Reputation: 3426
You can add a command using discord.ext.commands.
@bot.command(pass_context=True)
@bot.has_permissions(manage_roles=True)
async def add_role(ctx, role: discord.Role, *users: discord.Member):
for user in users:
await user.add_roles(role)
You should call it as follows {prefix}add_role @role @user1 @user2
Your setup should look like this
import discord
from discord.ext import commands, tasks
bot = commands.Bot(command_prefix="$")
#code here
bot.run("TOKEN")
Upvotes: 1