【发布时间】:2020-01-24 16:41:37
【问题描述】:
我想让 Discord 机器人为 ex 发送消息间隔。在 10 分钟内,但它会引发错误!请帮我! (对不起,我的英语并不完美)
代码如下:
const Commando = require('discord.js-commando');
const bot = new Commando.Client({commandPrefix: '$'});
const TOKEN = 'here is token';
const MIN_INTERVAL = 100;
bot.registry.registerGroup('connectc', 'Connectc');
bot.registry.registerGroup('defaultc', 'Defaultc');
bot.registry.registerDefaults();
bot.registry.registerCommandsIn(__dirname + "/commands")
bot.on('ready', function(){
console.log("Ready");
});
setInterval(function(){
var generalChannel = bot.channels.get("542082004821213197"); // Replace with known channel ID
generalChannel.send("Hello, world!") ;
}, MIN_INTERVAL);
bot.login(TOKEN);
它会抛出这个错误
PS C:\Users\User\Documents\Visual Studio Code\Discord Bots\VblacqeBot> node .
C:\Users\User\Documents\Visual Studio Code\Discord Bots\VblacqeBot\index.js:18
generalChannel.send("Eldo!") ;
^
TypeError: Cannot read property 'send' of undefined
at eldo (C:\Users\User\Documents\Visual Studio Code\Discord Bots\VblacqeBot\index.js:18:20)
at Object.<anonymous> (C:\Users\User\Documents\Visual Studio Code\Discord Bots\VblacqeBot\index.js:28:13)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)
PS C:\Users\User\Documents\Visual Studio Code\Discord Bots\VblacqeBot>
【问题讨论】:
-
Cannot read property 'send' of undefined表示bot.channels.get没有返回任何内容。
标签: node.js discord discord.js commando