#messageCreate isn't firing

24 messages Β· Page 1 of 1 (latest)

hollow epoch
#

I'm not getting messageCreate triggers when a message is sent in a chat channel.

To cover items from similar questions:

  • I've triple-checked my intents (see below)
  • I've got the "partials" thing in the code
  • The bot is in the server (/commands work)
  • The bot has access to all (one) channels
  • Perms are properly set in the bot portal

Relevant Code:

// create a new Client instance
const discord_client = new Client({
    intents: [
        GatewayIntentBits.DirectMessages,
        GatewayIntentBits.DirectMessageReactions,
        GatewayIntentBits.DirectMessages,
        GatewayIntentBits.DirectMessageTyping,
        GatewayIntentBits.Guilds,
        GatewayIntentBits.GuildMessageReactions,
        GatewayIntentBits.GuildMessages,
        GatewayIntentBits.GuildMessageTyping,
        GatewayIntentBits.MessageContent,
    ],
    partials: [
        Partials.Message,
        Partials.Channel,
    ]
});

// listen for the client to be ready
discord_client.once(Events.ClientReady, (c) => {
    console.log(`Ready! Logged in as ${c.user.tag}`);
});

// listen for general chat and respond
discord_client.on(Events.MessageCreate, async interaction => {
    console.log(`Responding to chat in ${interaction.channelId}`);
});

The log from the ClientReady event is seen as expected, but the log from MessageCreate never shows up at all.

Unless I'm totally understanding things, I should see that log every time someone writes something in the server where the bot is present, right?

tender kindleBOT
#
  • What's your exact discord.js npm list discord.js and node node -v version?
  • Not a discord.js issue? Check out #1081585952654360687.
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
dusty turretBOT
#

If you aren't getting any errors, try to place console.log checkpoints throughout your code to find out where execution stops.

  • Once you do, log relevant values and if-conditions
  • More sophisticated debugging methods are breakpoints and runtime inspections: learn more
cloud valve
#

In the ready event, can you log discord_client.channels.cache.get(<"channel_id">).viewable?

hollow epoch
#

Looks like that narrows the problem...

I added:

var count = discord_client.channels.cache.size;
console.log(`Channels: ${count}`);
if( count > 0 ){
    var temp = discord_client.channels.cache.get("general").isSendable();
    console.log(`Can send in #general: ${temp}`);
}

And it tells me the bot has 0 cached channels.

Now the question is why...

(Incidentally, viewable doesn't appear to be a property of channels.)

cloud valve
#

It’s a property of guild channels

#

You would need to cast or use the type guard

hollow epoch
#

Gotcha.

In any case, there's nothing in the collection there.

I've double checked the perms and they look right to me.

Any thoughts on what's missing?

cloud valve
#

Can you check the guilds cache?

hollow epoch
#

Sure thing πŸ™‚

It also reports being in 0 guilds.

#

(or there are zero in the cache at least - not sure if that means what I expect it to)

cloud valve
#

And this is being logged in the ready event?

hollow epoch
#

Yup:

// listen for the client to be ready
discord_client.once(Events.ClientReady, (c) => {
    console.log(`Ready! Logged in as ${c.user.tag}`);
    let count = discord_client.channels.cache.size;
    let gcount = discord_client.guilds.cache.size;
    console.log(`Channels: ${count}, Guilds: ${gcount}`);
    if( count > 0 ){
        let temp = discord_client.channels.cache.get("general");
        console.log(`Can see #general: ${(temp as GuildChannel).viewable}`);
    }
});
stark dune
#

Sounds like the part about the bot being in the server isn't true - you may have added the slash commands, or the slash commands are user installed, with the bot scope being enabled for that server

hollow epoch
# stark dune Sounds like the part about the bot being in the server isn't true - you may have...

I... think that makes sense, but I'm not entirely sure I actually understand πŸ˜„

In fact, I'm fully sure I don't completely understand...

Can you throw that at me in different words and/or speculate about how that happens and how to fix it?

I have verified that the /commands are in fact talking to this specific server and back by checking the server logs and changing the message sent back in response to a simple "ping" even to something unique.

stark dune
#

Slash commands use (or can use) a completely different system to adding the bot user to a server

#

The user is required for the guild (and its channels) to be in cache, and for regular events like messageCreate to be received and processed

#

If you only add its slash commands to the guild it will only receive and process interactionCreate events

hollow epoch
#

That makes sense, thanks.

Now I'm trying to figure out how to google that problem considering it contains almost no unique search terms πŸ˜„

stark dune
#

Its based on the scopes you defined when you add a bot to a server

#

"bot" is the bot user, "applications.commands" is the slash commands

#

So try re-adding it first with those scopes

ornate seal
hollow epoch
#

Thanks much - this was in fact the issue, and easily fixed with your guidance. πŸ™‚
Much appreciated to all who helped! β™₯️