Discord.py - Passing An Argument Role Functions
I wanted to create a command, like !iknow @user . A normal verification bot I think. Here's my code, I only pasted the important parts: import discord from discord.ext import comma
Solution 1:
You're looking for Member.remove_roles
and Member.add_roles
.
You can also specify that arg
must be of type discord.Member
, which will automatically resolve your mention into the proper Member
object.
Side note, it's no longer needed to specify pass_context=True
when creating commands. This is done automatically, and context
is always the first variable in the command coroutine.
import discord
from discord.ext import commands
client = commands.Bot(command_prefix='!')
@client.command()asyncdefiknow(ctx, arg: discord.Member):
await ctx.send(arg)
unknownrole = discord.utils.get(ctx.guild.roles, name="Unknown")
await arg.remove_roles(unknownrole)
knownrole = discord.utils.get(ctx.guild.roles, name="Verified")
await arg.add_roles(knownrole)
client.run('token')
Post a Comment for "Discord.py - Passing An Argument Role Functions"