首页 > 解决方案 > 绕过发送提醒的机器人的方法

问题描述

我是这样做的,如果您 p​​ing 所有者,我的机器人会发送一条消息说“不要 ping 所有者”,但有些人可以 ping 所有者,我想知道一种绕过机器人仅向某些人发送该消息的方法并定义人们通过他们的身份证

这是“不要 ping 所有者”的代码

const ownerId = "485705485757186050";

那就是定义ownerId,485705485757186050即所有者的ID

client.on("message", async message => {
    if (message.author.bot) return false;

    if (message.mentions.has(ownerId)) {
        message.reply(`dont ping the owner`);
    };
});

这就是机器人发送的实际信息

请帮我这样做

标签: discord.js

解决方案


有一个字符串数组保存可以绕过 ping 限制的人的 id

const bypassIds = ['id1', 'id2', 'id3'];

message.author.id应用 if所在的逻辑bypassIds(使用Array#includes()检查):不要回复。

if (message.mentions.has(ownerId) && !bypassIds.includes(message.author.id)) {
   message.reply(`dont ping the owner`);
};

推荐阅读