英文:
Check if command is in certain channel
问题
我有一个脚本,用于检查用户是否具有特定角色以查看是否可以使用特定命令。这些角色ID存储在一个JSON文件中,格式如下:
["roleid1", "roleid2", "roleid3"]
我想使用相同的概念来存储频道ID,但无法弄清楚如何做。以下是我的角色检查代码:
delete require.cache[require.resolve("./resources/lookup_perms.json")];
const roles = require("./resources/lookup_perms.json");
const result = msg.member.roles.cache.some(r => roles.includes(r.id));
Actions.storeValue(result, 1, "auth", cache);
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:
[ "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:
delete require.cache[require.resolve("./resources/lookup_perms.json")];
const roles = require("./resources/lookup_perms.json");
const result = msg.member.roles.cache.some(r => roles.includes(r.id));
Actions.storeValue(result, 1, "auth", cache);
Actions.callNextAction(cache)
答案1
得分: 1
不太确定你是如何做到这一切的,因为你没有展示你的所有代码,但是假设。我猜你正在尝试弄清楚如何检查频道?
就像你对角色所做的一样:
const result = msg.member.roles.cache.some(r => roles.includes(r.id));
你可以用相同的方法来处理频道
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:
const result = msg.member.roles.cache.some(r => roles.includes(r.id));
You can just do the same with channels
const result = msg.guild.channels.cache.some(ch => ch.includes(ch.id));
答案2
得分: 0
检查消息通道的ID
if (msg.channel.id === "在此处输入通道ID") {
// 在此处插入代码
}
将"在此处输入通道ID"替换为您想要的通道ID
编辑:
如果您想要检查多个通道,您可以使用.includes 方法,如下所示:
if (["通道ID1", "通道ID2"].includes(msg.channel.id))
{
// 在此处插入代码
}
英文:
Check the message channel id
if (msg.channel.id === "CHANNEL_ID_HERE") {
// Code here
}
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:
if (["ChannelId1", "ChannelId2"].includes(msg.channel.id))
{
// Code here
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论