Discord Bot语音播放器不会根据要求停止。帮助您将不胜感激

发布于 2025-02-09 00:17:54 字数 927 浏览 1 评论 0原文

我环顾四周,但没有骰子。机器人启动并拉出所需的缩略图,但在发出停止命令时无法停止:

client.on('messageCreate', async (message) => {
if (message.content && message.content.toLowerCase() === 'play baka radio') {
    if (!message.member.voice?.channel) return message.channel.send('You need to be a voice channel to execute this command')
          const connection = joinVoiceChannel({
        channelId: message.member.voice.channelId,
        guildId: message.guildId,
        adapterCreator: message.guild.voiceAdapterCreator
    })

    const player = createAudioPlayer()
    const resource = createAudioResource('https://nrf1.newradio.it:10328/alfaanime')

    connection.subscribe(player)

    message.channel.send({ content: "Now Playing", embeds: [embed2], files: ['./logo/bkrlogo.png'] }) + player.play(resource) 
if (message.content && message.content.toLowerCase() === 'stop')
player.stop(resource)   

    
}

i have looked around for an answer but no dice. bot starts and pulls the required thumbnail but fails to stop when the stop command is issued:

client.on('messageCreate', async (message) => {
if (message.content && message.content.toLowerCase() === 'play baka radio') {
    if (!message.member.voice?.channel) return message.channel.send('You need to be a voice channel to execute this command')
          const connection = joinVoiceChannel({
        channelId: message.member.voice.channelId,
        guildId: message.guildId,
        adapterCreator: message.guild.voiceAdapterCreator
    })

    const player = createAudioPlayer()
    const resource = createAudioResource('https://nrf1.newradio.it:10328/alfaanime')

    connection.subscribe(player)

    message.channel.send({ content: "Now Playing", embeds: [embed2], files: ['./logo/bkrlogo.png'] }) + player.play(resource) 
if (message.content && message.content.toLowerCase() === 'stop')
player.stop(resource)   

    
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

手长情犹 2025-02-16 00:17:54

您将不得不阅读以下内容: httpps:// https://discordjs.guide/popularjs.guide/popular-topics /collectors.html#await-messages 在使用Discord机器人时,它非常有用

。 filter filter,当某人发送“停止”时,触发了函数,并且播放器立即停止

const createPlayer = async (message) => {
  const connection = joinVoiceChannel({
    channelId: message.member.voice.channelId,
    guildId: message.guildId,
    adapterCreator: message.guild.voiceAdapterCreator,
  });

  const player = createAudioPlayer();
  const resource = createAudioResource(
    "https://nrf1.newradio.it:10328/alfaanime"
  );

  connection.subscribe(player);
  player.play(resource);

  await message.channel.send({
    content: "Now Playing",
  });

  const filter = (response) => response.content === "stop";
  await message.channel
    .awaitMessages({ filter, max: 1, time: 999999, errors: ["time"] })
    .then((askedStop) => {
      player.stop(resource);
    });
};

在这里,我只能调用我的函数createplayer,

client.on("messageCreate", async (message) => {
  if (message.content && message.content.toLowerCase() === "play baka radio") {
    if (!message.member.voice?.channel)
      return message.channel.send(
        "You need to be a voice channel to execute this command"
      );
    createPlayer(message);
  }
});

您可以选择在等待中设置时间

You will have to read this : https://discordjs.guide/popular-topics/collectors.html#await-messages its very usefull while working with discord bots

Here I ask my bot to watch the origin message (play baka radio) channel for a message who fit to my filter filter, when someone send "stop", the function is triggered and the player is instantly stopped

const createPlayer = async (message) => {
  const connection = joinVoiceChannel({
    channelId: message.member.voice.channelId,
    guildId: message.guildId,
    adapterCreator: message.guild.voiceAdapterCreator,
  });

  const player = createAudioPlayer();
  const resource = createAudioResource(
    "https://nrf1.newradio.it:10328/alfaanime"
  );

  connection.subscribe(player);
  player.play(resource);

  await message.channel.send({
    content: "Now Playing",
  });

  const filter = (response) => response.content === "stop";
  await message.channel
    .awaitMessages({ filter, max: 1, time: 999999, errors: ["time"] })
    .then((askedStop) => {
      player.stop(resource);
    });
};

Here I just call my function createPlayer

client.on("messageCreate", async (message) => {
  if (message.content && message.content.toLowerCase() === "play baka radio") {
    if (!message.member.voice?.channel)
      return message.channel.send(
        "You need to be a voice channel to execute this command"
      );
    createPlayer(message);
  }
});

You can choose to set time in the awaitMessages, or not

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文