我想执行命令,以便显示有关用户向机器人发出的邀请的信息。 但是当我尝试r!invitecheck时,僵尸程序没有响应,或者给出了错误。 我曾尝试在编码不一致的服务器上询问有人提供的帮助,但仍然无法正常工作。
这是代码
const args = msg.content.slice(prefix.length).trim().split(/ +/);
const command = args.shift();
switch (args[0]) {
case 'invitecheck':
if (!args.length) {
return msg.channel.send(`You didn't provide any arguments, ${message.author}!`);
}
client.fetchInvite(args[1])
.then(invite => {
const test12 = new Discord.MessageEmbed()
.setAuthor(invite.guild.name)
.addField(`Inviter`, ` ${invite.inviter.username} (<@${invite.inviter.id})>`)
.addField(`Total members`, invite.memberCount)
.addField(`Owner`, ` ${invite.guild.owner} (<@${invite.guild.ownerID}>)`)
.addField(`Region`, ` ${invite.guild.region}`)
.addField(`Verification level`, ` ${invite.guild.verificationLevel}`)
console.log(invite)
msg.channel.send(test12)
})
break;
}
答案 0 :(得分:0)
这是因为您如何声明命令Array.shift()
会删除数组的第一个元素,因此如果您检查命令,它将起作用:
const args = msg.content.slice(prefix.length).trim().split(/ +/);
const command = args.shift();
switch (command) {
case 'invitecheck':
if (!args.length)
return msg.channel.send(`You didn't provide any arguments, ${message.author}!`);
client.fetchInvite(args[0])
.then(invite => {
const test12 = new Discord.MessageEmbed()
.setAuthor(invite.guild.name)
.addField(`Inviter`, ` ${invite.inviter.username} (<@${invite.inviter.id})>`)
.addField(`Total members`, invite.memberCount)
.addField(`Owner`, ` ${invite.guild.owner} (<@${invite.guild.ownerID}>)`)
.addField(`Region`, ` ${invite.guild.region}`)
.addField(`Verification level`, ` ${invite.guild.verificationLevel}`)
console.log(invite)
msg.channel.send(test12)
})
break;
}