我用新代码编辑了问题
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('message', msg => {
if (msg.content === 'ping') {
msg.reply('Pong!');
}
});
client.login('token');
我希望我的漫游器在启动时或通过命令加入频道 有人可以帮助吗?
答案 0 :(得分:1)
这段代码将加入语音频道-将“ mychannelid”更改为所需的语音频道ID。
client.on("ready", () => {
const channel = client.channels.get("mychannelid");
if (!channel) return console.error("The channel does not exist!");
channel.join().then(connection => {
// Yay, it worked!
console.log("Successfully connected.");
}).catch(e => {
// Oh no, it errored! Let's log it to console :)
console.error(e);
});
});
此代码的信用转到用户@ FireController1847 在此Joining a voice channel on ready (discord.js)线程中