import asyncio
import discord
from discord.ext import commands
import random
TOKEN = 'youre not seeing this shit lmao' # the account token of AVNDB
intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix='!', intents=intents, case_insensitive=True)
@bot.event
async def on_ready():
print(f'We have logged in as {bot.user}!') # prints a message that shows the bot is online.
# above code logs the bot online
@bot.listen()
async def on_message(message):
hoontee = {71372475925008384}
username = str(message.author) # username variable
user_message = str(message.content) # user message variable
channel = str(message.channel.name) # channel variable
guild = str(message.guild.name) # server variable (guild = server)
user_ids_print = str(message.author.id)
print(f'{username} ({user_ids_print}): {user_message} (posted in "#{channel}" in "{guild}")') # when a message is sent, it enters this in the terminal.
# i.e "noradrenalines: Hello. (posted in #fortnite in Fortnite Official)
if message.author == bot.user:
return # ignores below code if message author is the bot
if message.author.id in hoontee:
await message.add_reaction('π«')
bot.run(TOKEN)```
#π Count reactions and ban message when certain amount of a certain reaction are hit.
218 messages Β· Page 1 of 1 (latest)
@toxic ravine
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
dont worry about the reason
inside joke bot
but
how do i make the bot autoban the person who sent a message if a message they send get a certain amount of a reaction (for example π€°)
bot.listen is fine
since when?
:sob
This is fine for listening to events
man someone told me to use bot.listen in 2022
!d discord.on_raw_reaction_add
discord.on_raw_reaction_add(payload)```
Called when a message has a reaction added. Unlike [`on_reaction_add()`](https://discordpy.readthedocs.io/en/latest/api.html#discord.on_reaction_add), this is called regardless of the state of the internal message cache.
This requires [`Intents.reactions`](https://discordpy.readthedocs.io/en/latest/api.html#discord.Intents.reactions) to be enabled.
i have dpy code somewhere from like 2020
Documentation explains when it fires
aaa
"this is called regardless of the state of the internal message cache."
cool
so its always called
yup, regular on_reaction_add only fires on messages in the cache
uhhh intents.reactions is enabled in theee
which maybe is what you want but often trips people up
intents are declared in code
privileged intents are enabled on the portal, and reactions isn't a privileged one
that's not how listening on events works
it always receives the same parameters. Inside of the listener you decide what you want to do and when
ah
you receive a Reaction and a Member/User
so i would add intents.reactions on line 8
assuming its not in default
reaction is just the emoji, what would member be?
message.author?
or however it is on dpy
reaction is the Reaction object, which has a bunch of information
Oh that's on the regular event, not the raw one mb
do you mind giving an example?
the raw one you get the full payload
this is a little confusing
Are you relying on this message being in the cache or not?
nope
it is just
if a guy sends a message
and enough people react it
with an emoji
they get banned
Right, and do you expect this to work on old messages
mmmm
yeah
sure
old messages assuming like
just old messages
or is therea meaning to that
the library only caches a limited set of recent messages. on_reaction_add will only fire if people react to one of those messages. on_raw_reaction_add will fire on any message, but have less data
old = like 30d+
It's based on the number of messages the bot sees, not necessarily their age
By default it's 1000 messages. If you want to listen on older messages, you'll want the raw event
Then you would implement on_reaction_add, which has parameters for Reaction and User (being the person who reacted)
!d discord.on_reaction_add
discord.on_reaction_add(reaction, user)```
Called when a message has a reaction added to it. Similar to [`on_message_edit()`](https://discordpy.readthedocs.io/en/latest/api.html#discord.on_message_edit), if the message is not found in the internal message cache, then this event will not be called. Consider using [`on_raw_reaction_add()`](https://discordpy.readthedocs.io/en/latest/api.html#discord.on_raw_reaction_add) instead.
Note
To get the [`Message`](https://discordpy.readthedocs.io/en/latest/api.html#discord.Message) being reacted, access it via [`Reaction.message`](https://discordpy.readthedocs.io/en/latest/api.html#discord.Reaction.message).
This requires [`Intents.reactions`](https://discordpy.readthedocs.io/en/latest/api.html#discord.Intents.reactions) to be enabled.
Note
This doesnβt require [`Intents.members`](https://discordpy.readthedocs.io/en/latest/api.html#discord.Intents.members) within a guild context, but due to Discord not providing updated user information in a direct message itβs required for direct messages to receive this event. Consider using [`on_raw_reaction_add()`](https://discordpy.readthedocs.io/en/latest/api.html#discord.on_raw_reaction_add) if you need this and do not otherwise want to enable the members intent.
So just
@bot.listen()
async def on_reaction_add(reaction: Reaction, user: Member):
...
what would user be
message.author
no message not defined
can i add it into my
@bot.listen() async def on_message(message):
@bot.listen()
async def on_reaction_add(reaction: ('π€°'), user: message.author):```
this is NOt working...
idk if i formatted it wrong
you always get those parameters in that event
nwnw
reaction not defined, member not defined
so it isnt in the common defines
so to line 8
i add
intents = discord.Intents.default(), discord.Intents.reactions()```
nope
hmm
let me try and find out
how to fix
discord.Intents.all()
you mean this member? in the user?
i found this on SO
@client.event
async def on_raw_reaction_add(payload):
if payload.channel_id == 614467771866021944:
if payload.emoji.name == "π":
channel = client.get_channel(payload.channel_id)
message = await channel.fetch_message(payload.message_id)
reaction = get(message.reactions, emoji=payload.emoji.name)
if reaction and reaction.count > 4:
await message.delete()```
if you want to use the raw event, sure
so is it member: User
typehinting isn't particularly needed
no. user: discord.Member
what is payload?
^
payload is the raw payload the bot recieves
hmm
but i dont want it to be in a specific channel
i want it to be in all channels
so i just delete line 3
then remove the first if
Then don't check the channel
im gonna go to bed. good luck with ur code
yes
does this work
async def on_raw_reaction_add(payload, reaction: discord.Reaction, user: discord.Member):
if payload.emoji.name == ":pregnant_woman:":
channel = bot.get_channel(payload.channel_id)
message = await channel.fetch_message(payload.message_id)
reaction = discord.get(message.reactions, emoji=payload.emoji.name)
if reaction and reaction.count > 20:
await message.author.ban()```
get didnt work on its own
i assumed it was a child of discord.py
you can't change the parameters.
as get(message.reactions, emoji=payload.emoji.name)
now its complaining to me
"get is not defined"
code?
maybe it was changed?
discord.get was never a thing as long as I've used the library
you wrote it lol
what are you trying to do with that line?
wait did i not send the stackoverflow thing
oh
i forgot to import
wow
im an idito
ok lets see
should work now
You don't need to count all emojis on a message
you just care about the current emoji being reacted
yes
that's on the payload
wdym
so itd be
if reaction > 20
ban
instead of and reaction count
im confused
then the payload only gives you the current reaction happening. You won't have metadata on the message, like other reactions on it
you would need to fetch the message to do that
ok so what do i do ?
sorry english isnt really my first language
i dont understand if i did something wrong or if youre just explaining
so i am guessing if reaction > 20:
or is it the other way round
or do i do nothing
idk man i misunderstand your mressage
sorry
So first you decide if you want to use the raw event
if you do, look at the payload object and see what it has
no i know what it does
but i dont know how i would do it without and i feel i am very close to being done
i just want to finish this now and go sleep :)
So what piece of information do you want out of it?
^
so now what's the question? How to get the number of a certain reaction on that message?
no
im asking if it works
like
if
will it ban someone if people react that emoji
on that message
example like this
20 ticks
and i get banned
that is my question
So do you know how to do this
no
i thought "reaction = get(message.reactions, emoji=payload.emoji.name)" did that though
well does it?
i dont know man!!!!
thats why i came here! to look for a quicker solution than google!
i dont know anything, i am just using what knowledge i had a few years ago. please just jist explain a little simply on what i should do
no quizzes
sorry if that sound rude
short of writing all of the code out for you, which I'm not going to do, you should be able to debug your code and see if it's behaving like you want it to
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.