最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Discordjs加入语音频道并说了些话然后离开语音频道

网站源码admin18浏览0评论

Discordjs加入语音频道并说了些话然后离开语音频道

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 !');
    }
  }
});
发布评论

评论列表(0)

  1. 暂无评论