我决定在node.js上制作一个discord机器人,我找到了那个库dicord.js
.我想让机器人接收来自用户的直接消息,但由于某种原因,它看不到直接发送给他的消息.
discord.js
版本:
npm view discord.js version
14.9.0
版本node
和npm
:
node -v
v18.15.0
npm -v
9.5.0
以下是我的代码:
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最近更新到了14版本,我没有找到适合我的工作选项.
如果有人知道我哪里搞砸了,我会非常感激的,提前谢谢.