【发布时间】:2020-09-02 23:29:11
【问题描述】:
我试图修改 discord.js 中的“乒乓”示例代码。
我不想登录控制台,而是想在 Discord 的特定频道中发送消息。
我曾尝试使用下面的代码来执行此操作,但它一直向我显示此错误:
(node:10192) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'channels' of undefined
at Client.<anonymous> (D:\GAMES\DiscordBot\index.js:7:12)
这是我正在使用的代码:
const Discord = require('discord.js');
const client = new Discord.Client();
console.log(client);
client.on('ready', client => {
client.channels.get('787667808777998851').send('Hello here!');
});
client.on('message', msg => {
if (msg.content === 'ping') {
msg.reply('pong');
}
});
client.login('auth-token');
【问题讨论】:
-
请编辑!您的令牌在您的问题中。
-
我在发布之前更改了令牌和频道 ID,所以这些都是但仍然感谢
标签: node.js bots discord discord.js