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

编程入门 行业动态 更新时间:2024-10-07 18:31:44

Discordjs加入<a href=https://www.elefans.com/category/jswz/34/1769309.html style=语音频道并说了些话然后离开语音频道"/>

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加入语音频道并说了些话然后离开语音频道

本文发布于:2024-05-07 14:38:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1756725.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:语音   说了   频道   Discordjs

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!