javascript - Leave Command Discord JS - Stack Overflow

Leave mand not working on my Discord bot which is written in JS.This is the snippet of code I'm us

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

This is the snippet of code I'm using.

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

However the mand 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 mand = message.content.substring(1).split(" ")[0];
		let args = message.content.substring(2 + mand.length);
        
        if(mand == 'leave') {
        client.leaveVoiceChannel; 
        } else if(mand == 'streams') {
			message.channel.createMessage(stations);
		} else if(mand == 'radio') {
			if(args == '') return message.channel.createMessage(`:exclamation: Please specify the radio stream example: **!radio <stream> or use mand **!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.`);                    
			}                
		}
	}
})

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

This is the snippet of code I'm using.

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

However the mand 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 mand = message.content.substring(1).split(" ")[0];
		let args = message.content.substring(2 + mand.length);
        
        if(mand == 'leave') {
        client.leaveVoiceChannel; 
        } else if(mand == 'streams') {
			message.channel.createMessage(stations);
		} else if(mand == 'radio') {
			if(args == '') return message.channel.createMessage(`:exclamation: Please specify the radio stream example: **!radio <stream> or use mand **!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.

Share Improve this question edited Mar 29, 2018 at 15:43 André 4,4974 gold badges32 silver badges58 bronze badges asked Sep 14, 2017 at 19:42 JohnJohn 732 gold badges3 silver badges9 bronze badges 2
  • Shouldn't that be client.leaveVoiceChannel()? Like, a function call? – Pointy Commented Sep 14, 2017 at 19:46
  • Thanks for your ment yes it is a function call. I managed to fix it. – John Commented Sep 14, 2017 at 20:14
Add a ment  | 

1 Answer 1

Reset to default 4

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744240235a4564671.html

相关推荐

  • javascript - Leave Command Discord JS - Stack Overflow

    Leave mand not working on my Discord bot which is written in JS.This is the snippet of code I'm us

    8天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信