语音频道并说了些话然后离开语音频道"/>
Discordjs加入语音频道并说了些话然后离开语音频道
我希望我的机器人加入指挥人所在的语音通道,然后说点什么然后离开,我尝试这样做但失败了。机器人加入了声音通道,但什么也没说。我该怎么办?
代码:
client.on('message', async message => {
if (!message.guild) return;
if (message.content.toLowerCase() === prefix + "bruh" ) {
if (message.member.voice.channel) {
const connection = await message.member.voice.channel.join();
} else {
message.reply('First of all you have to join an audio channel !');
const ytdl = require('ytdl-core');
connection.play(ytdl('', { filter: 'audioonly' }));
}
}
});
回答如下:您的机器人未播放该YouTube视频,因为您没有告诉它,因为您将play()
方法放置在else
语句中,而不是在其所属的if
语句中。
此外,在导入软件包时,重要的是,在文件的顶部而不是在代码的顶部,这是不正确的做法。
const ytdl = require('ytdl-core');
client.on('message', async message => {
if (!message.guild) return;
if (message.content.toLowerCase() === prefix + "bruh") {
if (message.member.voice.channel) {
const connection = await message.member.voice.channel.join();
connection.play(ytdl('https://www.youtube/watch?v=2ZIpFytCSVc', { filter: 'audioonly' }));
} else {
message.reply('First of all you have to join an audio channel !');
}
}
});
更多推荐
Discordjs加入语音频道并说了些话然后离开语音频道
发布评论