gpt4 book ai didi

javascript - 让 Discord Bot 加入/离开 channel

转载 作者:行者123 更新时间:2023-12-02 21:15:10 26 4
gpt4 key购买 nike

我用新代码编辑了问题

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');

我希望我的机器人在启动时或通过命令加入 channel 有人可以帮忙吗?

最佳答案

这段代码将加入语音 channel - 将“mychannelid”更改为您想要的语音 channel 的 ID。

client.on("ready", () => {
const channel = client.channels.get("mychannelid");
if (!channel) return console.error("The channel does not exist!");
channel.join().then(connection => {
console.log("Successfully connected.");
}).catch(e => {
console.error(e);
});
});

此代码的功劳归于用户@FireController1847在此Joining a voice channel on ready (discord.js)线程

关于javascript - 让 Discord Bot 加入/离开 channel ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60990748/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com