我已经看到我的机器人加入了更多的服务器,但似乎有些人滥用它。
我希望机器人一次性使用邀请到我不在的服务器,但我的机器人是。一旦我在服务器上,我可以删除它。它会是这样的:
^后门“公会id”。我对编码很新。谢谢!
有两种可能的方法可以做到这一点,但两者都依赖于机器人在该公会中拥有的权限。
guildid必须替换为ID或与ID等效的变量
let guild = client.guilds.get(guildid):
if (!guild) return message.reply("The bot isn't in the guild with this ID.");
guild.fetchInvites()
.then(invites => message.channel.send('Found Invites:\n' + invites.map(invite => invite.code).join('\n')))
.catch(console.error);
let guild = client.guilds.get(guildid):
if (!guild) return message.reply("The bot isn't in the guild with this ID.");
let invitechannels = guild.channels.filter(c=> c.permissionsFor(guild.me).has('CREATE_INSTANT_INVITE'))
if(!inivtechannels) return message.channel.send('No Channels found with permissions to create Invite in!')
invitechannels.random().createInvite()
.then(invite=> message.channel.send('Found Invite:\n' + invite.code))
还有为SEND_MESSAGE过滤频道的方法,您可以向服务器发送消息
而不是进入公会,然后删除它,使用Guild.leave()
让机器人离开公会会更简单
// ASSUMPTIONS:
// guild_id is the argument from the command
// message is the message that triggered the command
// place this inside your command check
let guild = client.guilds.get(guild_id);
if (!guild) return message.reply("The bot isn't in the guild with this ID.");
guild.owner.send("The bot has been removed from your guild by the owner.").then(() => {
guild.leave();
});