Discord.js Switch 中默认命令的问题
Discord.js Problems With Default Command in Switch
所以我正在尝试制作一个不和谐的机器人,并且我正在尝试设置一种方法让机器人在未定义输入但设置默认值时要求使用帮助命令在 switch 语句中,它只是一遍又一遍地重复自己,用输入的文本 @ing 自己。
switch(args[0]){
case 'ping':
message.channel.send('pong!');
break;
case 'rockLink':
message.channel.send('') //text here, deleted to protect link
break;
case 'info':
if(args[1] === 'description'){
message.channel.send('I am eventually going to play rock music, for now I do random stuff.')
}else if(args[1] === 'author'){
message.channel.send('I was made by IAmAGreenFlamingo')
}else if(args[1] === 'version'){
message.channel.send('This bot is in version ' + version)
}else{
message.channel.send('Invalid Argument, please use !help info to see all valid arguments!')
}
break;
case 'help':
if(args[1] === 'info'){
message.reply('Arguments for !info: description, author.')
}else{
message.reply('The commands so far are: !ping, !rockLink, and !info (use !help info for arguments)!')
}
break;
default:
message.reply('Invalid Argument, please use !help to see all commands!')
break;
}
忽略机器人和 DM 的命令是一种很好的做法。在 .on('message')
语句的顶部添加如下内容:
if(message.author.bot || !message.guild) return //ignores bot messages and pms
这也应该会阻止它自我应答。
另一种选择是将 message.reply
替换为 message.send
,这样它就不会标记自己或其他任何人。
所以我正在尝试制作一个不和谐的机器人,并且我正在尝试设置一种方法让机器人在未定义输入但设置默认值时要求使用帮助命令在 switch 语句中,它只是一遍又一遍地重复自己,用输入的文本 @ing 自己。
switch(args[0]){
case 'ping':
message.channel.send('pong!');
break;
case 'rockLink':
message.channel.send('') //text here, deleted to protect link
break;
case 'info':
if(args[1] === 'description'){
message.channel.send('I am eventually going to play rock music, for now I do random stuff.')
}else if(args[1] === 'author'){
message.channel.send('I was made by IAmAGreenFlamingo')
}else if(args[1] === 'version'){
message.channel.send('This bot is in version ' + version)
}else{
message.channel.send('Invalid Argument, please use !help info to see all valid arguments!')
}
break;
case 'help':
if(args[1] === 'info'){
message.reply('Arguments for !info: description, author.')
}else{
message.reply('The commands so far are: !ping, !rockLink, and !info (use !help info for arguments)!')
}
break;
default:
message.reply('Invalid Argument, please use !help to see all commands!')
break;
}
忽略机器人和 DM 的命令是一种很好的做法。在 .on('message')
语句的顶部添加如下内容:
if(message.author.bot || !message.guild) return //ignores bot messages and pms
这也应该会阻止它自我应答。
另一种选择是将 message.reply
替换为 message.send
,这样它就不会标记自己或其他任何人。