离开Command Discord JS

时间:2017-09-14 19:42:28

标签: javascript node.js discord

让命令无效,我的Discord bot是用JS编写的。

这是我正在使用的代码片段。

if(command == 'leave') { client.leaveVoiceChannel;

然而,应该使机器人离开语音通道的命令似乎不起作用。以下是我使用代码的方式。



const Eris = require('eris');
const client = new Eris(require('./config.json').token, { maxShards: 1 });
fs = require('fs')
var stations = fs.readFileSync("./stations.txt", {"encoding": "utf-8"}).toString()
client.connect();
client.on('ready', () => {
	console.log('Ready to go!')
})
client.on('messageCreate', message => {
	if(message.author.bot) return;
	if(message.content.startsWith('!')) {
		let command = message.content.substring(1).split(" ")[0];
		let args = message.content.substring(2 + command.length);
        
        if(command == 'leave') {
        client.leaveVoiceChannel; 
        } else 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.`);
			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 Streaming station **${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.`);                    
			}                
		}
	}
})
&#13;
&#13;
&#13;

我不知道我在哪里出错了。

1 个答案:

答案 0 :(得分:1)

 if(command == 'stopstream') {
        client.leaveVoiceChannel(message.member.voiceState.channelID);
        message.channel.createMessage(`Thanks for tuning in!`); }