简体   繁体   English

discord.js 对播放功能的反应

[英]discord.js reaction for play function

I am pretty sure it means message is not defined but why I think I defined it does anyone know what is the problem?我很确定这意味着没有定义消息,但为什么我认为我定义了它有没有人知道问题是什么? I tried everything I can.我尽我所能。 it sends this error (There was an error connecting to the voice channel: TypeError: Cannot read property 'react' of undefined)它发送此错误(连接到语音通道时出现错误:类型错误:无法读取未定义的属性“反应”)

function play(guild, song, client, message) {
    const serverQueue = client.queue.get(guild.id)
    const loop = client.loop.get(guild.id)

    console.log(loop)

    if (!song) {
        serverQueue.voiceChannel.leave()
        client.queue.delete(guild.id)
        return
    }

    const dispatcher = serverQueue.connection.play(ytdl(song.url))
        .on('finish', () => {
            if (loop === undefined) {
                serverQueue.songs.shift()
            }
            play(guild, serverQueue.songs[0], client, message)
        })
        .on('error', error => {
            console.log(error)
        })
    dispatcher.setVolumeLogarithmic(serverQueue.volume / 5)
    if (loop === undefined) {
        const reaction = (reaction) => reaction.emoji.name === '⏭️';
        serverQueue.textChannel.send(`Playing: **${song.title}**`)
        message.react('⏭️') 
        .then(console.log) 
        .catch(console.error);
    message.awaitReactions((reaction) => (reaction.emoji.name == '⏭️'),
            { max: 1 }).then(collected => {
            if (collected.first().emoji.name == '⏭️') {
              if(!message.member.voice.channel) return message.channel.send("You need to be in a voice channel to skip the music")
                 if(!serverQueue) return message.channel.send("There is nothing to playing")
                  serverQueue.connection.dispatcher.end()
                   client.loop.delete(message.guild.id)
                         }
     return undefined
    
        
    })
    }
}

You are right.你是对的。 Inside play(<args>){...} function you try to call .react() on undefined .play(<args>){...}函数中,您尝试在undefined上调用.react() Could you give more context to this problem?你能给这个问题提供更多的背景吗? Like the calling context to see why play(<args>){} receives no value for its 4th parameter, message.就像调用上下文一样,看看为什么play(<args>){}的第四个参数 message 没有收到任何值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM