我有这个脚本可以踢用户。如何更改该脚本,以便按用户ID踢用户?
脚本:
const discord = require('discord.js');
const client = new discord.Client;
const prefix = "$";
client.on('message', function(message) {
if (!message.content.startsWith(prefix)) { return }
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
if(command === "kick") {
let member = message.mentions.members.first();
let reason = args.slice(1).join(" ");
if (member) { // add this
member.kick(reason);
client.channels.cache.get('737341022782357566').send("User <@" + member.id +
"> with id " + member.id + " has been kicked by <@" + message.author.id +
"> with reason " + reason)
} else {
message.reply("invalid parameters for $kick")
}
message.delete();
}
})
client.login('token');
答案 0 :(得分:0)
您必须通过ID获取成员:
const Member = message.guild.members.cache.get('MemberId')
if (!Member) return console.log(`Invalid member.`);
然后踢他们:
Member.kick("Reason").catch(error => {
console.log(`Couldn't kick ${Member.user.tag}.`);
})