I want to compare :
user from on_reaction_add(reaction, user) on DM channel
member (which is saved by on_message on some guild before, member = message.author. )
but message.author seems it does not hold the ID of the DM channel. Then how do I compare member and user?
Related
#client.command()
async def find(ctx):
guild = ctx.message.guild
role = discord.utils.get(ctx.guild.roles,name="Palpatin")
for member in guild.members:
if role in member.roles :
await ctx.send(f'{member}')
await member.remove_roles(role)
When I try to use the code there are no errors but the bot doesn't send what member has the role either removes the role from that member
As #Weylyn said, your variable role might be None if there is no role named exactly Palpatin, if that is the case, your if will always be evaluated to False since None in any list will always be False, this might be why you do not get any message nor any error.
Also, your for might not work if you do not have the member intents enabled (check here https://discordpy.readthedocs.io/en/stable/intents.html )
I wanted to add a role every time a user levels up.
But, I am getting an error: TypeError: add_roles() got an unexpected keyword argument 'role'. This is the code i have right now:
if users[f'{user.id}']['level'] == 2:
role_id = 833924720617062430
await user.add_roles(user, role = role_id)
member.add_roles(), takes just the roles as the parameter, not role ids or member instances.
# getting the role
role = user.guild.get_role(role_id)
if role is None:
print('invalid role id')
await user.add_roles(role)
Note: this only works if user is a discord.Member instance
References:
get_role
add_roles
discord.py, Can I get a user ID using just the user's name?
I want to know the syntax
utils.find? MemberConverter?
discord.Guild.get_member_named?
If you have a guild object then you can
member = discord.utils.get(guild.members, name="name")
member_id = member.id
So I want to use a command that only I can do and link it so I can us my User Id, like
#commands.has_any_role()
But with my user ID
A simple solution is to check your own id, and use an if statement to check the user's id:
it's been quite a while since I've done discord.py, but here's my crack at it:
# Set your id here
my_id = 1234567890
async def my_command(ctx):
if ctx.author.id == my_id:
// do something
To create your custom decorator for multiple commands, just define it:
# Set your id here
my_id = 1234567890
is_me = commands.check(lambda ctx: ctx.author.id == my_id)
#commands.command()
#is_me
async def command():
// do something
The benefit of having a custom decorator is that it reduces the indentation required AND can apply to multiple functions.
How do I perform the highest role of a user among some roles?
For example I have this category of roles:
And I wish that when I go to see a user's information, the highest role among them comes out?
You can reverse Member.roles and find the first match:
#bot.command()
async def my_highest_role(ctx):
highest = discord.utils.find(lambda role: role in my_roles, reversed(ctx.author.roles))
if highest:
await ctx.send(highest.name)
else:
await ctx.send("No such role")