can someone tell me how I can show back or print the number of members of a role?... I've been looking around but almost everything is either too complicated or out-dated...
By default bots can't see everyone in guild.members, only themselves. You will want to use Intents to fix this intents = discord.Intents.all() client = discord.Client(intents=intents) You will also need to enable it on the discord application page for your bot, you will get an error starting the bot otherwise. Once that is done, the code he wrote in the video should work. See here for additional details: stackoverflow.com/questions/64148371/discord-bot-can-only-see-itself-and-no-other-users-in-guild
Hello i neeed help i'm lost at 11:21 "if role is not None : print(role.name)" With me, the program don't run with that I don't get the answer when i put an emoji reaction Can anybody help me ?
I may be wrong here, maybe not. I found though that this didnt work with built in emojis. I had to use custom ones added to the server. Side note, did anyone have issues with it not removing roles? I copy/pasted and changed it to member.remove_roles but to no effect.
Another note. Not sure how his remove works, but from what I read myself and others ran into an issue where adding roles worked but not removal. From what I can see, documentation says the remove function doesn't pass in a 'member' object with the payload. I think there are some work around but that's likely beyond me.
to do it with the build in emojis is weird. what you want to do is in the on_raw_reaction_add function, add a line that says print(payload.emoji.name). if you react to the message with the built in emoji's, the output should give you the emoji you could copy and paste into the function
by the way if you have probelms with adding roles go to server settings, roles and drag the bot role at the top but below the owner rank if you have one
@@zeral1317 actually nevermind you need to put it on the top of the highest role of the options of the bot NOT OVER THE OWNER Sorry for miscommunication
Hey this is very helpful... but I want to know how to make reaction role or level up message or join or leave server message configured by the user... using a website...like we do in MEE6 or Carl or Dyno
I keep getting guild references before assignment errors on discord.utils.get(guild.roles, name=payload.emoji.name) UnboundLocalError: Local Variable ‘guild’ referrenced before assignment
You're reacting to the wrong message. The if statement defines the variable "guild" *if* the message id is whatever you put there. If the message id *is not* that, then the variable won't get defined.
I've followed the thing using the if statement if the names are different, but it only seems to work with one of the roles I've done this for. Strange 🤔
ayyy thanks for the video but u probably shouldn't have revealed the tocken I mean anyone could see it in ur code but hey thanks for the video I was able to improve my friend's server with the bot I made for his server and everyone was able to get the role I wanted them to!
It works perfectly to add a role when I replace member = discord.utils.find(lambda m : m.id == payload.user_id, guild.members) by member = payload.member. BUT when I copy-paste the code for remove the role, it don't work. He find the member for adding a role but he says "Member not found" when he try to remove a role. Can someone help me ?
here is my code @client.event async def on_raw_reaction_add(payload): message_id = payload.message_id if message_id == "798520336039149578": guild_id = payload.guild_id guild = discord.utils.find(lambda g : g.id == guild_id, client.guilds) role = discord.utils.get(guild.roles, name=payload.emoji.name) if role: member = discord.utils.find(lambda m : m.id == payload.user_id, guild.members) if member: await member.add_role(role) print('done') else: print('Member not found.') else: print('Role not found.')
what did this error mean? emoji = PartialEmoji.with_state(self, animated=emoji_data['animated'], id=emoji_id, name=emoji_data['name']) KeyError: 'animated'
By default bots can't see everyone in guild.members, only themselves. You will want to use Intents to fix this intents = discord.Intents.all() client = discord.Client(intents=intents) You will also need to enable it on the discord application page for your bot, you will get an error starting the bot otherwise. Once that is done, the code he wrote in the video should work. See here for additional details: stackoverflow.com/questions/64148371/discord-bot-can-only-see-itself-and-no-other-users-in-guild
@@JR-ub2wt rip homie. I just spent the last hour trying to figure out why my bot didn't have the right perms to assign roles before I realized the chronological order of the roles actually affects the permissions hierarchy. What a mundane yet important detail.
@@JR-ub2wt You could make a list of IDs and check if the payload message_id is in that list using something like if id in list: where id is the payload's message_id and list is the list of allowed IDs
hi at first let me tnx for your great tutorials but i have a problem when i add reactions i get this error role not found i joined ur server but i diding get help that would be kind of u if you help please
by the way, yah code from like a year a go is gonna be a little outdated :/ i also have an error and od so whenever i check out anything that old. but yeah and good luck (:
Just add intents in the beginning of your code and the rest should be good intents = discord.Intents.default() intents.members = True client = commands.Bot(command_prefix="{bot_prefix}", intents=intents)
can someone please upload that code somerwhere so i can download it, my code wont work and i didnt know whats the issue. if i join the discord server from the video maker, i cant write in ANY channel and the mod isn responding. Its a Cool video and it helped me out for real
Hey, the code here is a bit outdated. I found the solution. Instead of member = discord.utils.find(lambda m : m.id == payload.user_id, guild.members) use member = payload.member
The above comment will work for adding a role, but to remove the role you will want this: intents = discord.Intents.all() client = discord.Client(intents=intents) You will also need to enable it on the discord application page for your bot, you will get an error starting the bot otherwise. Once that is done, the code he wrote in the video should work. See here for additional details: stackoverflow.com/questions/64148371/discord-bot-can-only-see-itself-and-no-other-users-in-guild
what if you want this to work with more than one person?? the on_raw_reaction_add only works when a reaction is added not the 2nd..... time that same reaction is used
So reacting works. My terminal is spitting out this error over and over.. role = discord.utils.get(guild.roles, name = payload.emoji.name) Unboundlocalerror: local variable ‘guild’ referenced before assignment I’ve looked through the comments and tried everything I could find here. Yes, I have intents in the code and enabled in my dev portal. Again, I react and I get the role so it appears to work, but the error just keeps coming up. As for un reacting it doesn’t work. Nothing happens. Had an error say “member not found”
Autor thx for tutorial, i work in cogs and have this porblem > all work fine but bot cant find guild member and i have this print "Member not found." can you give me answer what is happen? thx alot
Thanks for the video :)
I'm glad it still works in 2023
Thanks for the help, took me ages to find a good tutorial for this!
Thanks for the amzing video! Helped a lot!
can someone tell me how I can show back or print the number of members of a role?... I've been looking around but almost everything is either too complicated or out-dated...
Is everyone going to ignore how many bots he has in his server?
Its just 15
and its his tutorial bots..
@@Zirzux Yeah okay smartass. Take a joke lmao
it's the first thing that i noticed
@@N1ghtM0ntagna Good for you..
Love the tutorials especially the nodejs ones. Helps me out a lot. Ty :)
:) Thank you for the feedback.
@@ansonthedev The github link seems broken. Can you please fix it?
12:40 you could just use **if member:** instead of **if member is not None:**
if member: checks if member is True, not not None, It would be correct for if member is not False
I am getting no warnings but just getting an error " Parameter 'payload' value is not used" what can be the cause of this?
Well, either you didn't pass payload, or missed it in one of the variables assigned.
GUYS use member = await(await client.fetch_guild(payload.guild_id)).fetch_member(payload.user_id) it works better
tysm
Thanks for that, it solves my problem and works well!
QUE CARA FODA!
Thank you!!! This solved my problem!
what the hell thanks man, this is amazing! Why doesnt his code work for this?
Helped me a lot. Works as intended. Thanks. :)
For some reason my bot cannot find me, it keeps giving me the "Member not found" message, how do I fix this?
By default bots can't see everyone in guild.members, only themselves. You will want to use Intents to fix this
intents = discord.Intents.all()
client = discord.Client(intents=intents)
You will also need to enable it on the discord application page for your bot, you will get an error starting the bot otherwise. Once that is done, the code he wrote in the video should work.
See here for additional details: stackoverflow.com/questions/64148371/discord-bot-can-only-see-itself-and-no-other-users-in-guild
@@WolfeWinters thank you so much!!
@@WolfeWinters Where would I insert this in the code?
@@WolfeWinters this man saving lives, ty
when i try to use the remove_roles function it says "AttributeError: 'NoneType' object has no attribute 'remove_roles'"
for me it work perfectly for the on_raw_reaction_add but not for the on_raw_reaction remove, it give me "member not found" help please :( !
same
any luck finding a solution?
member = await(await client.fetch_guild(payload.guild_id)).fetch_member(payload.user_id)
use this
@@tonycipher5078 omgggggg tyy after A FUCKING YEAR i can finally do it
it's not working for me occurs an error: "local variable 'role' referenced before assignment"
pls help me
I mean I just can't get the role
I checked my bot's permission it's administrator so he can manage the roles
Just put the bots role over the admin role
thanks
@@zarkiber no problem
@Michael Benedict wdym?
Hello i neeed help
i'm lost at 11:21
"if role is not None :
print(role.name)"
With me, the program don't run with that
I don't get the answer when i put an emoji reaction
Can anybody help me ?
I may be wrong here, maybe not. I found though that this didnt work with built in emojis. I had to use custom ones added to the server.
Side note, did anyone have issues with it not removing roles? I copy/pasted and changed it to member.remove_roles but to no effect.
Another note. Not sure how his remove works, but from what I read myself and others ran into an issue where adding roles worked but not removal. From what I can see, documentation says the remove function doesn't pass in a 'member' object with the payload. I think there are some work around but that's likely beyond me.
@@seldian yeah i got the same problem, it can't find member through the payload
to do it with the build in emojis is weird. what you want to do is in the on_raw_reaction_add function, add a line that says print(payload.emoji.name). if you react to the message with the built in emoji's, the output should give you the emoji you could copy and paste into the function
by the way if you have probelms with adding roles go to server settings, roles and drag the bot role at the top but below the owner rank if you have one
Thank you, this saved me a lot of time!
@@zeral1317 actually nevermind you need to put it on the top of the highest role of the options of the bot NOT OVER THE OWNER
Sorry for miscommunication
@@ColliefarmerYT I believe that you don’t need an owner role since the user who owns the server has all the permissions even without any roles anyway
@@zeral1317 yeah bot if you somehow are coding for a very big server you shouldn't put it above owner and bot
This is awesome! Thanks!
it would be cool if you can do more of a video where you can make your own so you don't have to keep coding it when you want a new one
yeeeees i want one too
Help, my bot can only add roles but not remove them
OMG thank you it worked
how do you make it so you can only select one role and not multiple of the same message
Hey this is very helpful... but I want to know how to make reaction role or level up message or join or leave server message configured by the user... using a website...like we do in MEE6 or Carl or Dyno
I keep getting guild references before assignment errors on discord.utils.get(guild.roles, name=payload.emoji.name) UnboundLocalError: Local Variable ‘guild’ referrenced before assignment
guild = guild.member
You're reacting to the wrong message. The if statement defines the variable "guild" *if* the message id is whatever you put there. If the message id *is not* that, then the variable won't get defined.
Worked fine, thanks
Thank you sir. I subscribe.
How do i give someone 2 roles with this?
I've followed the thing using the if statement if the names are different, but it only seems to work with one of the roles I've done this for. Strange 🤔
2:16
who else thought the sound came from their own computer?
its says the role isnt found when the role is found
did u found the resolution for this (having the same problem)
Could you teach us how to do the same thing but with a command? For example: "!reactionrole (messageID) (@role) (emoji)"
Thank you.
@Ender777456 you forgot the argument of the emoji
@@BaroShirts added it xd
Wanting to know the exact same thing! Got any response or answer?
@@F8P nope
Change the names etc
In this video he uses custom emotes and when I try to use default emotes it does not work is there a work around for that?
guys i need help
in line 24
it shows an error (find missing one positional argument: seq)
What version of VSCode are you using?
Keep getting this error :((. : UnboundLocalError: local variable 'discord' referenced before assignment
love you!
Dont work with the normal emoji
Like :joy:
ROOT BEER it should work with normal emojis, they don’t have an ID so you’d have to just include the emoji name with colons in between.
@@ansonthedev I am doing something wrong?
elif payload.emoji.name == 'joy':
@@ROOTBEEROFF Please join my Discord server, it'll be much easier to help you that way. discord.gg/bZSwjPy
I always have member not found ...
hi man, could you possibly make a tutorial on how to host a java discord bot online 24/7 on site like heroku?
Thanks for the suggestion! I'll definitely look into it.
@@ansonthedev nice, i'm really looking forward it as I struggle immensly with trying to host my own bot online
Not too hard really.
ayyy thanks for the video but u probably shouldn't have revealed the tocken I mean anyone could see it in ur code but hey thanks for the video I was able to improve my friend's server with the bot I made for his server and everyone was able to get the role I wanted them to!
You can change the token.. that's what he did lmao
A common solution is to make it retrieve it from a .env file so that it stays safe and secure
It just says "Member not found" for me
Apparently, when you remove the reaction, it doesn't track you as a member. The only valid way to track the member, is using payload.user_id.
@@GeorgeMC2610 did you found any fixes if yes pls dm me on discord TheMeliodas#2779
awesome video
when i run the code it has no errors but when i add a role it says i am missing permissions (error 50013)
Same issue here
upd
I found a solution. You should check if ur bot role is higher then the role u want to give
Can someone help. the remove_roles(role) doesnt work
use member = await(await client.fetch_guild(payload.guild_id)).fetch_member(payload.user_id)
@@Neoproxy_ Thanks a lottt
It works perfectly to add a role when I replace member = discord.utils.find(lambda m : m.id == payload.user_id, guild.members) by member = payload.member.
BUT when I copy-paste the code for remove the role, it don't work. He find the member for adding a role but he says "Member not found" when he try to remove a role.
Can someone help me ?
Same issue here
@@seldian yeah
yeah i got no clue on that, tryna figure it out rn
Make sure if it's in a cog you passed in self everywhere you need it that was my issue
@@sorenoneil3876 my solution was to add text to the message saying “if you’d like a role removed please message an admin” LMAO
I got a problem too, if i do @client.event he tells me that a coroutine is not given but i thought on_raw_reaction_add is the coro
Did you write @client.event() or @client.event
?
it didnt work
ty for the video
You can do a function to get the role and user you want to add it
its just straight up not working for me no errors nothing it just isnt assigning the role is this tutorial with rewrite or nah?
here is my code
@client.event
async def on_raw_reaction_add(payload):
message_id = payload.message_id
if message_id == "798520336039149578":
guild_id = payload.guild_id
guild = discord.utils.find(lambda g : g.id == guild_id, client.guilds)
role = discord.utils.get(guild.roles, name=payload.emoji.name)
if role:
member = discord.utils.find(lambda m : m.id == payload.user_id, guild.members)
if member:
await member.add_role(role)
print('done')
else:
print('Member not found.')
else:
print('Role not found.')
nice video but your voice is so funny lmao
what did this error mean? emoji = PartialEmoji.with_state(self, animated=emoji_data['animated'], id=emoji_id, name=emoji_data['name'])
KeyError: 'animated'
Your emoji_data dictionary doesn't have a key named 'animated' in it.
i cant remove roles its keeping saying member not found
By default bots can't see everyone in guild.members, only themselves. You will want to use Intents to fix this
intents = discord.Intents.all()
client = discord.Client(intents=intents)
You will also need to enable it on the discord application page for your bot, you will get an error starting the bot otherwise. Once that is done, the code he wrote in the video should work.
See here for additional details: stackoverflow.com/questions/64148371/discord-bot-can-only-see-itself-and-no-other-users-in-guild
AttributeError: 'RawReactionActionEvent' object has no attribute 'message'
On the "message_id = payload.message.id" line
It should be:
message_id = payload.message_id
@Zarkiber is right, whenever you get the "Attribute" Error message, it's because you put a "." instead of a "_".
I have :
role = discord.utils.get(guild.roles, name=payload.emoji.name)
AttributeError: 'NoneType' object has no attribute 'roles'
Can you help me ?
you need to define guild
i think its something like payload.guild.roles
can someone tell me how to use this but with several message ids
A messy way would just to make a different event for each message ID.
Czar.J that’s what I’m trying to avoid lmao
@@JR-ub2wt rip homie. I just spent the last hour trying to figure out why my bot didn't have the right perms to assign roles before I realized the chronological order of the roles actually affects the permissions hierarchy. What a mundane yet important detail.
Czar.J you could also just use administrator for people you want to use the roles instead of specific role perms
@@JR-ub2wt You could make a list of IDs and check if the payload message_id is in that list using something like
if id in list:
where id is the payload's message_id and list is the list of allowed IDs
hi at first let me tnx for your great tutorials but i have a problem when i add reactions i get this error role not found i joined ur server but i diding get help that would be kind of u if you help please
by the way, yah code from like a year a go is gonna be a little outdated :/ i also have an error and od so whenever i check out anything that old. but yeah and good luck (:
mine didn´t work
Ehm "Member not Found" why?
member = await(await client.fetch_guild(payload.guild_id)).fetch_member(payload.user_id)
use this
How do you use intents in this code can someone plz help
Just add intents in the beginning of your code and the rest should be good
intents = discord.Intents.default()
intents.members = True
client = commands.Bot(command_prefix="{bot_prefix}", intents=intents)
where is a link to github
Thanks so much!
can you give the command
can someone please upload that code somerwhere so i can download it, my code wont work and i didnt know whats the issue. if i join the discord server from the video maker, i cant write in ANY channel and the mod isn responding. Its a Cool video and it helped me out for real
How do i have to do if i want to use discord emojis, not mine
do a backslash behind the emojis
@@anirvdh thanks
@@Totema. omg you are still here ok well np
@@anirvdh could you explain?
@@joshua.s255 \:emoji_name:
source code?
why does it say member is None type
Hey, the code here is a bit outdated. I found the solution.
Instead of
member = discord.utils.find(lambda m : m.id == payload.user_id, guild.members)
use
member = payload.member
The above comment will work for adding a role, but to remove the role you will want this:
intents = discord.Intents.all()
client = discord.Client(intents=intents)
You will also need to enable it on the discord application page for your bot, you will get an error starting the bot otherwise. Once that is done, the code he wrote in the video should work.
See here for additional details: stackoverflow.com/questions/64148371/discord-bot-can-only-see-itself-and-no-other-users-in-guild
what if you want this to work with more than one person??
the on_raw_reaction_add only works when a reaction is added not the 2nd..... time that same reaction is used
Not true.
How to add several messages?
@@passi2437 where exaclty??
you can just put a comma after the first message id and then another message id
Where's the link to GitHub?
In the description idiot
@@aristology6912 u don’t have to get mad at that
@@aristology6912 theres nothing on the description
So reacting works. My terminal is spitting out this error over and over..
role = discord.utils.get(guild.roles, name = payload.emoji.name)
Unboundlocalerror: local variable ‘guild’ referenced before assignment
I’ve looked through the comments and tried everything I could find here.
Yes, I have intents in the code and enabled in my dev portal. Again, I react and I get the role so it appears to work, but the error just keeps coming up.
As for un reacting it doesn’t work. Nothing happens. Had an error say “member not found”
The error means that you referenced guild after the guild code ran.
You are a god! Thank you.
lifesaver c:
Does anyone know the theme
*hyper i hyper-material-theme* thats the theme from the hyper command promt if you want it
Are this still working ?
@Mango outdated or something
@@jh1an394 not working.
@@Acrissmester not working
Github not working! ;D
True it show us a 404 error
True it show us a 404 error
You have #0001 as your tag? Just how OG are you?
its nitro lmao
Autor thx for tutorial, i work in cogs and have this porblem > all work fine but bot cant find guild member and i have this print "Member not found." can you give me answer what is happen? thx alot
solution is add new discord api intents
intents = discord.Intents.all()
bot = commands.Bot(command_prefix=settings['prefix'], intents=intents)
Please use node.js
I have the same tutorial on my channel using Discord.js & Node.
I keep getting Role Not Found. Please help
too dont know
and this is oudated now ! yes !!
nope
@@ansonthedev I tried today
it told me that "guild_id" is not a part of "Member" class
@@antonkortial4635 You probably mistyped, the code works fine. I coded it up today and everything works
@@ansonthedev it doesn’t work now without intents, RIP
is noone gonna speak about how much hes voice cracks
Thanks a lot!
I keep getting member not found when running this.
Im getting "Role not found" could u help me?