检查命令是否在特定频道中。

huangapple go评论130阅读模式
英文:

Check if command is in certain channel

问题

我有一个脚本,用于检查用户是否具有特定角色以查看是否可以使用特定命令。这些角色ID存储在一个JSON文件中,格式如下:

  1. ["roleid1", "roleid2", "roleid3"]

我想使用相同的概念来存储频道ID,但无法弄清楚如何做。以下是我的角色检查代码:

  1. delete require.cache[require.resolve("./resources/lookup_perms.json")];
  2. const roles = require("./resources/lookup_perms.json");
  3. const result = msg.member.roles.cache.some(r => roles.includes(r.id));
  4. Actions.storeValue(result, 1, "auth", cache);
  5. Actions.callNextAction(cache);

请注意,我已经删除了代码中的HTML转义字符(")。

英文:

I have a script that checks if a user has a certain role to see if they can use a certain command. Those role ids are stored in a json file like so:

  1. [ "roleid1", "roleid2", "roleid3" ]

i would like to use the same concept to store the channel ids, but cannot figure out how. this is the code for my role checking:

  1. delete require.cache[require.resolve("./resources/lookup_perms.json")];
  2. const roles = require("./resources/lookup_perms.json");
  3. const result = msg.member.roles.cache.some(r => roles.includes(r.id));
  4. Actions.storeValue(result, 1, "auth", cache);
  5. Actions.callNextAction(cache)

答案1

得分: 1

不太确定你是如何做到这一切的,因为你没有展示你的所有代码,但是假设。我猜你正在尝试弄清楚如何检查频道?

就像你对角色所做的一样:

  1. const result = msg.member.roles.cache.some(r => roles.includes(r.id));

你可以用相同的方法来处理频道

  1. const result = msg.guild.channels.cache.some(ch => ch.includes(ch.id));
英文:

Not really sure how you are doing all of that as you are not showing all of your code, but BY ASSUMING. I guess you are trying to figure out how to check the channels?

Just like you did with your roles:

  1. const result = msg.member.roles.cache.some(r => roles.includes(r.id));

You can just do the same with channels

  1. const result = msg.guild.channels.cache.some(ch => ch.includes(ch.id));

答案2

得分: 0

检查消息通道的ID

  1. if (msg.channel.id === "在此处输入通道ID") {
  2. // 在此处插入代码
  3. }

将"在此处输入通道ID"替换为您想要的通道ID

编辑:
如果您想要检查多个通道,您可以使用.includes 方法,如下所示:

  1. if (["通道ID1", "通道ID2"].includes(msg.channel.id))
  2. {
  3. // 在此处插入代码
  4. }
英文:

Check the message channel id

  1. if (msg.channel.id === "CHANNEL_ID_HERE") {
  2. // Code here
  3. }

Replace CHANNEL_ID_HERE with the channel id you want

Edit:
If you want to check an array of channels you can use .includes like this:

  1. if (["ChannelId1", "ChannelId2"].includes(msg.channel.id))
  2. {
  3. // Code here
  4. }

huangapple
  • 本文由 发表于 2023年8月5日 02:55:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/76838529.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定