question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

messageCreate not triggered on DM in main

See original GitHub issue

Which package is this bug report for?

discord.js

Issue description

  • Listen in messageCreate
  • provide proper intents (DirectMessages from gateway bits)
  • send message to bot from private account
  • event not triggered

Code sample

import { Client, GatewayIntentBits } from 'discord.js';
const client = new Client({
  'intents': [
    GatewayIntentBits.DirectMessages,
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildPresences,
    GatewayIntentBits.GuildMembers,
    GatewayIntentBits.GuildBans,
    GatewayIntentBits.GuildMessages
  ],
  'partials': ['CHANNEL']
});

process.on('uncaughtException', (err) => {
  console.log('General error:', err.message);
  console.log(err);
});

client.on('messageCreate', async (m) => {
  console.log(m);
});

client.login('TOKEN');

Package version

14.0.0-dev.1647259751.2297c2b with https://github.com/discordjs/discord.js/pull/7649 apply’d

Node.js version

v16.14.2

Operating system

Debian

Priority this issue should have

Medium (should be fixed soon)

Which partials do you have configured?

Channel

Which gateway intents are you subscribing to?

Guilds, GuildMembers, GuildBans, GuildPresences, GuildMessages, DirectMessages

I have tested this issue on a development release

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
Jiralitecommented, Mar 22, 2022

Unfortunately, that’s not how one applies partials. Import the partial like so:

import { Partials } from "discord.js";
Partials.Channel; // 1
1reaction
renedxcommented, Mar 22, 2022

Unfortunately, that’s not how one applies partials. Import the partial like so:

import { Partials } from "discord.js"
Partials.Channel; // 1

Aha, thats changed too? Thanks.

Works. Wow, I’ve found all bit changes, but this one overlooked. Thanks for the amazingly quick reply. 😃

For future reference, this is how DM channels work under v14;

import { Client, GatewayIntentBits, Partials } from 'discord.js';
const client = new Client({
  'intents': [
    GatewayIntentBits.DirectMessages,
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildPresences,
    GatewayIntentBits.GuildMembers,
    GatewayIntentBits.GuildBans,
    GatewayIntentBits.GuildMessages
  ],
  'partials': [Partials.Channel]
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Event messageCreate not firing/emitting when I send a DM to ...
The bot has to send at least one DM to the user first. Then the messageCreate is firing as usual. Not sure if...
Read more >
Discord.js v14 - Listening and Handling Events - YouTube
Join my Discord for more help: https://discord.gg/Gd5fAEJDQDCode: https://github.com/stuyy/djs-v14-tutorialSupport the Channel:Become a ...
Read more >
Gateway Intents - discord.js Guide
If you do not specify intents, discord.js will throw an error. ... to receive messages ( MESSAGE_CREATE - "messageCreate" in discord.js), ...
Read more >
Gateway - Discord Developer Portal
You need to cache the most recent non-null s value for heartbeats, ... The bot owner(s) will receive a system DM and email...
Read more >
How to Make a Discord Bot: An Overview and Tutorial - Toptal
There are two main reasons. Querying the REST API to get user information every time a Message Create event is received, for example,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found