【发布时间】:2021-07-07 15:59:09
【问题描述】:
我还没有更好地掌握 Node.js,但是当我在修改我的 Discord 机器人时,我似乎无法找到一种方法来获取机器人所在的频道列表而不放置它在 EventEmitter 中。我很困惑为什么这不起作用,有什么我遗漏的吗?
代码:
const Discord = require("discord.js");
const client = new Discord.Client();
require('dotenv').config();
//this works
client.on('ready', ()=> {
const channelID = '803359668054786118';
const channel = client.channels.cache.get(channelID);
channel.send('working'); //this works
});
//this doesn't work
//intially tried using a wait function to see if the reason was because bot didn't have enough time to log on properly
setTimeout(function() {
const channelID = '803359668054786118';
const channel = client.channels.cache.get(channelID);
console.log(client.channels); //this is telling me that there's no channels in the collection...
//channel.send('working');
}, 500);
【问题讨论】:
标签: node.js discord discord.js