discord.js v14.9.0机器人无法接收用户私信的问题求助
我最近打算用Node.js做一个Discord机器人,选了discord.js库,版本是14.9.0。现在遇到个头疼的问题:机器人完全接收不到用户发的私信,我特意把所有能开的intents和partials都加上了,可还是没反应。
先贴一下我的环境版本:
- Node.js版本:
v18.15.0(用node -v查到) - npm版本:
9.5.0(用npm -v查到) - discord.js版本:
14.9.0(用npm view discord.js version查到)
下面是我的主代码:
import discord from 'discord.js'; import config from './config.js'; const bot = new discord.Client({intents: config.intents, partials: config.partials}) bot.on('ready', () => { console.log(`Logged in as ${bot.user.tag}!`); }); bot.on('messageCreate', (message) => { console.log(message); }); bot.login(config.token);
还有config.js的内容:
import discord from 'discord.js' const { GatewayIntentBits, Partials } = discord export default { "token": xxxxxxx, "intents": Object.keys(GatewayIntentBits), "partials": [Object.keys(Partials)] }
我本来期望当用户给机器人发私信时,控制台能输出类似这样的消息对象:
<ref *1> Message {
channelId: '1101904091908689970',
guildId: '1101895271669055611',
id: '1102197229973938348',
createdTimestamp: 1682854697460,
type: 0,
system: false,
content: 'Hello',
author: User {
id: 'xxxxxxxx',
bot: false,
system: false,
flags: UserFlagsBitField { bitfield: 0 },
username: 'sewrprvrt',
discriminator: 'xxxx',
avatar: '49891ad2803d523d6edf79dd41b72ecb',
banner: undefined,
accentColor: undefined
},
pinned: false,
tts: false,
nonce: '1102197239196942336',
embeds: [],
components: [],
attachments: Collection(0) [Map] {},
stickers: Collection(0) [Map] {},
position: null,
roleSubscriptionData: null,
editedTimestamp: null,
reactions: ReactionManager { message: [Circular *1] },
mentions: MessageMentions {
everyone: false,
users: Collection(0) [Map] {},
roles: Collection(0) [Map] {},
_members: null,
_channels: null,
_parsedUsers: null,
crosspostedChannels: Collection(0) [Map] {},
repliedUser: null
},
webhookId: null,
groupActivityApplication: null,
applicationId: null,
activity: null,
flags: MessageFlagsBitField { bitfield: 0 },
reference: null,
interaction: null
}
我试过查各种资料,但大多是针对discord.js旧版本的解决方案,新版本似乎有不少变化,那些方法都不管用。有没有大佬能帮我看看哪里出问题了?提前谢谢大家!
备注:内容来源于stack exchange,提问作者Sewerprvrt

