【问题标题】:Discord.js Backdoor commandDiscord.js 后门命令
【发布时间】:2020-06-23 23:15:21
【问题描述】:

我已经看到我的机器人加入了更多的服务器,但似乎有些人在滥用它。

我希望机器人向我不在但我的机器人在的服务器发出一次性使用邀请。一旦我在服务器上,我就可以删除它。应该是这样的:

^后门“公会ID”。我对编码很陌生。谢谢!

【问题讨论】:

  • 你需要一个频道来创建邀请,所以 guild.channels.first().createInvite() 稍微调整一下应该会很好discord.js.org/#/docs/main/stable/class/…
  • 所以我试过 client.guilds.get('474317783740579872').guild.channels.first().createInvite() 它没有工作。还有什么?

标签: node.js discord discord.js


【解决方案1】:

有两种可能的方法,但都依赖于机器人在该公会中的权限。

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(!invitechannels) 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频道的方法,您可以向服务器发送消息。

【讨论】:

    【解决方案2】:

    使用Guild.leave()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();
    });
    

    【讨论】:

    • 嗯,我有点想和店主一对一谈谈,但非常感谢。
    • 哦,好的。问题是您需要创建邀请的权限,而许多服务器拒绝向机器人授予该权限,因此没有一致的方式来做您想做的事情:\
    • 我试过在我自己的服务器上使用它,机器人有烫发,仍然不知道如何
    猜你喜欢
    • 1970-01-01
    • 2020-12-04
    • 2021-06-01
    • 2021-03-29
    • 2022-01-27
    • 2022-01-25
    • 2021-05-20
    • 2021-04-18
    • 2021-06-11
    相关资源
    最近更新 更多