【问题标题】:Issue with message output消息输出问题
【发布时间】:2017-09-19 13:54:31
【问题描述】:

您好,我正在开发一个机器人,它可以在 Discord 上的语音频道中播放播客和流媒体。当机器人不在语音频道中并且成员使用命令 !stopstream 时,我遇到了一个小问题,它应该输出消息“没有流播放”,但是它继续输出消息“停止!感谢调整”这应该只在使用 !stopstream 命令停止流时输出,该命令使机器人离开语音通道。

这是我正在使用的 sn-p

client.leaveVoiceChannel(message.member.voiceState.channelID);
message.channel.createMessage(`:stop_button: Stopped! Thanks for tuning in :wave:`);
if(client.leaveVoiceChanne == null)
    return message.channel.createMessage(`:exclamation: No Stream Playing.`);

这是我在代码中的使用方式

if (command == 'stopstream') {
     if (!message.member.voiceState.channelID)
         return message.channel.createMessage(`:exclamation: You have to join the voice channel to stop the stream.`);
     client.leaveVoiceChannel(message.member.voiceState.channelID);
     message.channel.createMessage(`:stop_button: Stopped! Thanks for tuning in :wave:`);
     if (client.leaveVoiceChanne == null)
         return message.channel.createMessage(`:exclamation: No Stream Playing.`);
 }
 if (command == 'streams') {
     message.channel.createMessage(stations);
 } else if (command == 'radio') {
     if (args == '')
         return message.channel.createMessage(`:exclamation: Please specify the radio stream example: **!radio <stream>** or use command **!streams** to see list. Use **!streamhelp** to show commands list.`);
     if (require('./stations.json')[args]) {
         if (!message.member.voiceState.channelID)
             return message.channel.createMessage(`:exclamation: You need to be in a voice channel to play that stream.`);
         client.joinVoiceChannel(message.member.voiceState.channelID).then(vc => {
             if (vc.playing) vc.stopPlaying();
             message.channel.createMessage(`:radio: You are listening to **${args}**. To change the stream use **!radio <stream>**`);
             vc.play(require('./stations.json')[args]);
         })
     } else {
         return message.channel.createMessage(`:frowning2: I cannot find a radio stream with that name. Make sure it has capitals and the correct spelling. Type **!streams** to see stream list.`);
     }
}

看来我在这里做错了,不胜感激。

【问题讨论】:

    标签: javascript node.js discord


    【解决方案1】:

    在检查流是否正在播放之前,您正在发送“流停止”消息。在此之前移动支票:

    if (!message.member.voiceState.channelID)
      return message.channel.createMessage(`:exclamation: You have to join the voice channel to stop the stream.`);
    else if (client.leaveVoiceChanne == null)
      return message.channel.createMessage(`:exclamation: No Stream Playing.`);
    client.leaveVoiceChannel(message.member.voiceState.channelID);
    message.channel.createMessage(`:stop_button: Stopped! Thanks for tuning in :wave:`);

    【讨论】:

    • 仍然没有运气,因为这似乎只是在 bot 正在流式传输时输出“No Stream Playing”,而不是实际停止并输出消息“停止!感谢您调整:wave:”如果我删除了else if (client.leaveVoiceChannel == null) return message.channel.createMessage(:exclamation: No Stream Playing.); 这行,但是当机器人离开语音频道时,它显然只是返回“停止!感谢您调整:wave:”这不是我想要的做,但谢谢你的回复。
    • 是您在else if (client.leaveVoiceChannel == null) 上面的评论中所说的,还是我刚刚意识到else if (client.leaveVoiceChanne == null) 在您的原始问题和我的回复中?如果是后者,则 client.leaveVoiceChanne 将未定义,因此等于 null。
    猜你喜欢
    • 2013-12-12
    • 1970-01-01
    • 2011-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-30
    • 1970-01-01
    • 2020-06-28
    相关资源
    最近更新 更多