I'm creating a discord reaction bot which assigns members roles depending on which reaction emoji they use.
I've found discord.utils.find
works as expected when running the app locally, but doesn't find a member when the app is hosted on Heroku or ibmcloud.
@client.event
async def on_raw_reaction_remove(payload):
message_id = payload.message_id
#...
#...
#...
# payload.member is not available for REACTION_REMOVE event type
member = discord.utils.find(lambda m: m.id == payload.user_id, guild.members)
member2id = int(payload.user_id)
GetMember = discord.Guild.get_member()
RoleLoser = GetMember(member2id)
To get around this I'm trying to search the member list for a given guild and return a member using their member id. But running the above prompts the following with reference to this line GetMember = discord.Guild.get_member()
No value for argument 'self' in unbound method call
No value for argument 'user_id' in unbound method call
Really appreciate any help!
InsertCheesyLine is correct. Here is the working code:
@client.event
async def on_raw_reaction_add(payload):
# channel and message IDs should be integer:
if payload.channel_id == 700895165665247325 and payload.message_id == 757114312413151272:
if str(payload.emoji) == "<:Apex:745425965764575312>":
guild = client.get_guild(payload.guild_id)
member = guild.get_member(payload.user_id)
role = get(payload.member.guild.roles, name='Apex')
await payload.member.add_roles(role)
print(f"Assigned {member} {role}.")
I've added a print statement that is sent to the console when the user is assigned a role. Simply replace the id's and role name and you're all set. Refer to where I asked this question and got help solving it (along with the code to remove the role when the reaction is removed): Assign discord role when user reacts to message in certain channel