Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.9k views
in Technique[技术] by (71.8m points)

python - In discord.py, the on_message does not trigger for one guild

I'm trying to figure out how to write a simple bot for Discord. However, the problem I'm facing is that for one particular server (or guild as it is called), I don't get any messages.

I am logged in this guild in the webinterface with the same user. And I see messages coming in.

However, in the client I do not see anything being logged.

The code is very simple:

import discord

class DiscordClient(discord.Client):
    async def on_ready(self, *args, **kwargs):
        print(f"Connected as {self.user.display_name} to:")

        for guild in self.guilds:
            print(f"- {guild.name}")

    async def on_message(self, message):
        print(f"Message from '{message.guild.name}'")

DiscordClient().run(TOKEN, bot=False)

In the on_ready, I can see it knows the guild and even the channels. So that's fine. There is a connection...

The server is the "Among Us" server which has 500k users. So maybe it's a limitation because too much users? As the on_message does trigger correctly for servers with much more limited amount of users (like 20k or so).

What setting should I adjust to connect to this server in order to receive the messages?

Thanks!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I don't see any issue with your code tbh, maybe it's an intents issue (?), try enabling some basic intents

intents = discord.Intents.default()

DiscordClient(intents=intents).run(TOKEN, bot=False)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...