gpt4 book ai didi

JavaScript:使用 !kick 命令时出现 Discord.js 错误

转载 作者:行者123 更新时间:2023-12-03 12:18:15 24 4
gpt4 key购买 nike

我一直在升级我以前的所有命令,以使用嵌入而不是正常响应进行响应。

const Discord = require('discord.js')
const client = new Discord.Client({ws: {intents: Discord.Intents.ALL}});

exports.run = async (bot,message,args) => {
let member = message.mentions.members.first() || message.guild.members.cache.get(args[0])
let reason = args.slice(1).join(' ');

let embed1 = new Discord.MessageEmbed()
.setTitle(`You Do Not Have The Permissions For This Command!`)
.setDescription(`<@!${message.member.user.id}> you are not an Admin`)
.setColor('#eeff00')
.setFooter(`Bot is maintained by BLADEZ#7296`)
let embed2 = new Discord.MessageEmbed()
.setTitle(`InValid User`)
.setDescription(`<@!${message.member.user.id}> please give a valid User \n **Remember** !kick [@User] [reason]`)
.setColor('#eeff00')
.setFooter(`Bot is maintained by BLADEZ#7296`)
let embed3 = new Discord.MessageEmbed()
.setTitle(`Kick Unsuccessful`)
.setDescription(`<@!${message.member.user.id}> you can not kick this person!`)
.setColor('#eeff00')
.setFooter(`Bot is maintained by BLADEZ#7296`)
let embed4 = new Discord.MessageEmbed()
.setTitle(`Kick Successful`)
.setDescription(`**<@!${member.user.id}>** has been **kicked** for **${reason}** by **<@!${message.author.id}>**`)
.setColor('#eeff00')
.setFooter(`Bot is maintained by BLADEZ#7296`)


if(!message.member.hasPermission("MANAGE_ROLES")) return message.channel.send(embed1)

if(member) return message.channel.send(embed2)

if(member.roles.highest.position > message.member.roles.highest.position) return message.channel.send (embed3)
if(!reason) {reason = 'No reason given'}
member.kick(reason)
message.channel.send(embed4);
console.log(`**${member.user.tag}** has been kicked for ${reason} by ${message.author.tag}`)
}

exports.help = {
name: 'kick'
}

所以这是我使用的代码,我没有更改,只是添加了嵌入。^

enter image description here

但是我得到了这个错误^。如果我在 !kick 之后不包含用户,Kick 仍然有效。

最佳答案

您尝试使用 member.user.id,但如果没有提及成员,member 将是 undefined

如果您只使用其中一个,则实际上不需要创建所有这些嵌入。当您确定值可用时,在 if 语句中创建它们。

只声明嵌入并更新它就足够了。

exports.run = async (bot, message, args) => {
let member =
message.mentions.members.first() ||
message.guild.members.cache.get(args[0]);
let reason = args.slice(1).join(' ');

let embed = new Discord.MessageEmbed()
.setColor('#eeff00')
.setFooter(`Bot is maintained by BLADEZ#7296`);

if (!message.member.hasPermission('MANAGE_ROLES')) {
embed
.setTitle(`You Do Not Have The Permissions For This Command!`)
.setDescription(`<@!${message.member.user.id}> you are not an Admin`);

return message.channel.send(embed);
}

// are you sure you want to check if member exists?
// if (member) should be if (!member)
if (!member) {
embed
.setTitle(`InValid User`)
.setDescription(
`<@!${message.member.user.id}> please give a valid User \n **Remember** !kick [@User] [reason]`,
);
return message.channel.send(embed);
}

if (member.roles.highest.position > message.member.roles.highest.position) {
embed
.setTitle(`Kick Unsuccessful`)
.setDescription(
`<@!${message.member.user.id}> you can not kick this person!`,
);
return message.channel.send(embed);
}

embed
.setTitle(`Kick Successful`)
.setDescription(
`**<@!${member.user.id}>** has been **kicked** for **${reason}** by **<@!${message.author.id}>**`,
);

if (!reason) {
reason = 'No reason given';
}

member.kick(reason);
message.channel.send(embed);
console.log(
`**${member.user.tag}** has been kicked for ${reason} by ${message.author.tag}`,
);
};

它似乎按预期工作:

enter image description here

关于JavaScript:使用 !kick 命令时出现 Discord.js 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66126556/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com