简体   繁体   中英

Leave Command Discord JS

Leave command not working on my Discord bot which is written in JS.

This is the snippet of code I'm using.

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

However the command which should make the bot leave the voice channel does not seem to work. Here is how I'm using the code.

 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.`); } } } }) 

I'm not sure where I'm going wrong here.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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