[英]How do I add a command where it bans the user in all the servers the bot is in?
I am trying to make a command using discord.js that would execute a command on multiple servers.我正在尝试使用 discord.js 发出命令,该命令将在多个服务器上执行命令。 this is what I have done so far.
这就是我迄今为止所做的。
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;
}
I am not sure on how to continue this.我不确定如何继续。
well, just have the bot loop through all the guilds it's in and search for that user.好吧,让机器人遍历它所在的所有公会并搜索该用户。 I could try giving you some code, but idk what version of discord.js you are using.
我可以尝试给你一些代码,但我知道你使用的是什么版本的 discord.js。
EDIT: in discord.js v12 --->编辑:在 discord.js v12 --->
client.guilds.cache.forEach(a => a.members.cache.get(targetID.)ban()
client.guilds.cache.forEach(a => a.members.ban(targetID))
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)
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.