我正在尝试使用discord.js发出命令,该命令将在多个服务器上执行命令。 这是我到目前为止所做的。
if (isCommand('globalban', message)) {
if(!member.roles.cache.some(role => role.name === 'Staff'))
return message.reply("You can't use this command.");
var targetID = args[1]; // this is the targets UserID
if (!targetID)
return message.channel.send("Please provide the targets ID");
//rest of code goes here.
return;
}
我不确定该如何继续。
答案 0 :(得分:0)
好吧,让机器人遍历它所在的所有公会并搜索该用户。我可以尝试为您提供一些代码,但请问一下您使用的是哪个版本的discord.js。
编辑:在discord.js v12中--->
client.guilds.cache.forEach(a => a.members.cache.get(targetID.)ban()
答案 1 :(得分:0)
client.guilds.cache.forEach(a => a.members.ban(targetID))
答案 2 :(得分:0)
const { MessageEmbed } = require("discord.js");
const Owner = require("../config.json")
module.exports = {
name: "globalban",
description: "bans the user from all servers the bot is in",
aliases: "gb",
execute(message, args, client){
const targetID = args[0];
const reason = args.slice(0).join(' ')
if(!message.author === Owner) return message.channel.send("You need to be bot owner to use this command");
else{
client.guilds.cache.forEach(a => a.members.ban(targetID));
const embed = new MessageEmbed()
.setTitle(`Successfully banned`)
.setDescription(`I have successfully banned ${targetID.tag} from all servers`)
.setColor("#FF0000")
.setThumbnail("https://cdn.discordapp.com/emojis/764396593964122132.gif?v=1")
message.channel.send(embed)
const dmembed = new MessageEmbed()
.setTitle("You have been banned from all the servers i am in")
.setDescription('Your Crime was `${reason}`. If you want to apeal, You may join [Appeal Server by Clicking here](https://discord.gg/ZWWYy37atN)')
.setColor("#FF0000")
message.targetID.send(embed)
}
}
}