0

我制作了一个音乐机器人,但我希望将其转化为交互,但我在调用播放函数时遇到了问题。

使用“消息”它可以工作,但使用“交互”它不会。我试图传递一些信息,我搜索但我不能。

我什至找到了另一种方法,但它没有用。

返回的错误是这样的:

DisTubeError [INVALID_TYPE]: Expected 'Discord.Message' for 'message', but got undefined (undefined)

Play.js

const { SlashCommandBuilder } = require('@discordjs/builders');

module.exports = {
  data: new SlashCommandBuilder()
        .setName('play')
        .setDescription('Play a song!')
    .addStringOption(option => option.setName('song').setDescription('Enter name of the music.')),

  async execute (interaction, client){
    // if(!interaction.member.voice.channel) return interaction.reply("Please, join a voice channel!");

    const music = interaction.options.getString('song');
    if(!music) return interaction.reply("Please, provide a song!");
    
    await client.distube.play(interaction, music);

    // await client.distube.playVoiceChannel(
    //   interaction.member.voice.channel,
    //   music,
    //   { 
    //     textChannel: interaction.channel,
    //     member: interaction.member
    //   }
    // );
  }
}
4

1 回答 1

2

DisTube,在发布这个问题的时候,不支持斜线命令,看起来创作者没有任何正式支持它的计划。作为一种解决方法,您可以使用Distube#playVoiceChannel方法而不是Distube#play方法,如下所示:

await client.distube.playVoiceChannel(interaction.member.voice.channel, music);

但在你做任何这些之前,它看起来interaction是未定义的——这可能是你的命令处理程序的问题,所以看看那里。

编辑:如果您有兴趣,还有文档Distube#playVoiceChannel

于 2021-12-05T04:33:55.830 回答