#๐Ÿ”’ why the on_message event not working?

53 messages ยท Page 1 of 1 (latest)

tardy narwhalBOT
#

@ivory basin

Python help channel opened

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.

ivory basin
#

!paste

tardy narwhalBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

ivory basin
shadow folio
#

You leaked your bot token btw

ivory basin
#

shit at least i didnt leak my ip port ad pwd

shadow folio
#

Doesn't message.channel.send need await?

ivory basin
#

right but the prints dont run either

rotund kestrel
#
    if message.author == client.user:
        return```
#

make sure the bot doesnt trigger on message

#

and put a print outside the if statement to see if on_message works in the first place

ivory basin
ivory basin
rotund kestrel
#

remove the else part and put print("sad") outside of the if statement for now

#

run it again and lmk how it goes

ivory basin
#

still nothing happens

rotund kestrel
#

what is this part

with mcrcon.MCRcon(HOST,PWD,PORT) as server:
ivory basin
#

it starts an rcon connection to my mc server bc this bot is supposed to send commands to it

rotund kestrel
#

yeah ive never used it before, so if on_message isnt working because of it then idk what else it could be

ivory basin
#

huh i removed it and than the check function runs and it prints ran

#

i see just now that also didnt run until now

#

i added the with in the duncs separately and the check runs the bot runs but the on_message dont work

brave yoke
#

I'll assume you refreshed your bot token

#

Could this be an intents issue

#

!intents

tardy narwhalBOT
#
Using intents in discord.py

Intents are a feature of Discord that tells the gateway exactly which events to send your bot. Various features of discord.py rely on having particular intents enabled, further detailed in its documentation. Since discord.py v2.0.0, it has become mandatory for developers to explicitly define the values of these intents in their code.

There are standard and privileged intents. To use privileged intents like Presences, Server Members, and Message Content, you have to first enable them in the Discord Developer Portal. In there, go to the Bot page of your application, scroll down to the Privileged Gateway Intents section, and enable the privileged intents that you need. Standard intents can be used without any changes in the developer portal.

Afterwards in your code, you need to set the intents you want to connect with in the bot's constructor using the intents keyword argument, like this:

from discord import Intents
from discord.ext import commands

# Enable all standard intents and message content
# (prefix commands generally require message content)
intents = Intents.default()
intents.message_content = True

bot = commands.Bot(command_prefix="!", intents=intents)

For more info about using intents, see discord.py's related guide, and for general information about them, see the Discord developer documentation on intents.

ivory basin
brave yoke
ivory basin
#

it says premissions=8

brave yoke
#

that's different to intents

ivory basin
#

and says that when i specify scope bot premissions Administrator

ivory basin
brave yoke
#

if you want all the intents then you can do discord.Intents.all()

#

you also need to make sure you've enabled them in the developer portal

ivory basin
#

Shard ID None is requesting privileged intents that have not been explicitly enabled in the developer portal. It is recommended to go to https://discord.com/developers/applications/ and explicitly enable the privileged intents within your application's page. If this is not possible, then consider disabling the privileged intents instead.

Discord Developer Portal

Integrate your service with Discord โ€” whether it's a bot or a game or whatever your wildest imagination can come up with.

brave yoke
#

intents is a separate thing in the portal

ivory basin
ivory basin
#

ah so its different for slash and prefix commands and ect

#

thx it works now

brave yoke
#

๐Ÿ‘

ivory basin
#

by any chance do u know how to get all the users currently in a vc?

brave yoke
ivory basin
brave yoke
#

it should, a VoiceChannel is a type of GuildChannel

ivory basin
#

when i run it i get
Exception has occurred: AttributeError
'NoneType' object has no attribute 'members'
File "/home/opc/python/console.py", line 15, in check
members=bot.get_channel(1226117248154861572).members
File "/home/opc/python/console.py", line 25, in <module>
check(10)
AttributeError: 'NoneType' object has no attribute 'members'
for members=bot.get_channel(1226117248154861572).members

#

and i am sure the id is correct

#

1226117248154861572
right click the channel
click copy channel id how could i get an in valid channel with that

#

!close

tardy narwhalBOT
#
Python help channel closed

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.