discord.js - 绕过发送提醒的机器人的方法
问题描述
我是这样做的,如果您 ping 所有者,我的机器人会发送一条消息说“不要 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`);
};
});
这就是机器人发送的实际信息
请帮我这样做
解决方案
有一个字符串数组保存可以绕过 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`);
};
推荐阅读
- local-storage - 从待办事项列表+本地存储中删除任务
- python - 熊猫图中的基本趋势线
- numpy - 如何矢量化将 PyTorch 张量中的所有非零值复制到最左侧位置而没有任何间隙的操作?
- c++ - 比较字符总是输出假,即使它应该是真的
- python - 如何使用 Python zeep 从具有多个绑定的 Python Soap 客户端访问所有 Web 服务方法
- rest - BitBucket 服务器 Rest API 调用以获取 2 个标签之间合并的拉取请求列表
- javascript - WebAudio API:是否可以使用 StereoPanner 节点数据导出 AudioBuffer?
- visual-studio-code - 如何隐藏 VS Code 在花括号后放置的竖线?
- regex - Elisp regexp 如何在换行符后匹配文本?
- bash - 在 Dockerfile 中, RUN /bin/mkdir -p /root/lib/{sh,pl,py,rb} 未能达到预期