【发布时间】: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