Node.js 如何让用户在一个频道中只说一次话?
所以我想弄清楚如何让会员在特定的频道里只说一次话。当我使用Node.js 如何让用户在一个频道中只说一次话?,node.js,discord,discord.js,Node.js,Discord,Discord.js,所以我想弄清楚如何让会员在特定的频道里只说一次话。当我使用.overwrite命令时,出现一个错误,说明: client.overwritePermissions( ^ TypeError: client.overwritePermissions is not a function 我也只希望它在一个频道工作,但我没有运气 这是我剩下的代码 const Discord = require('discord.js'); const client = new Discord
.overwrite
命令时,出现一个错误,说明:
client.overwritePermissions(
^ TypeError: client.overwritePermissions is not a function
我也只希望它在一个频道工作,但我没有运气
这是我剩下的代码
const Discord = require('discord.js');
const client = new Discord.Client();
const prefix = '';
let lastUser = undefined;
client.once('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('message', message => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
lastUser = `${message.author}`
client.overwritePermissions(
lastUser,
{ 'SEND_MESSAGES': false },
)
});
client.login(''); //bot token
client.overwritePermissions()
不存在,但它确实存在于。overwritePermissions,如名称和文档所示,但我无法理解,会覆盖最后一个值。因此,为了不断向覆盖添加新用户,您需要复制以前的值,然后添加到该值上:
client.on("message", message => {
if (message.author.bot) return;
if (message.channel.name == "support") {
let ow = message.channel.permissionOverwrites.array(); //get the information of the current permission overwrites, as an array
ow.push({ //add our data object to the end of this array
id: message.author.id,
deny: ["SEND_MESSAGES"]
});
message.channel.overwritePermissions(
ow //pass this array as our new overwrites
);
}
});
overwritePermission
获取对象的数组。这些是我们推到上一次覆盖上的对象。对象被记录下来。当其他人说话时,它允许用户发送消息。我不知道你说的其他人允许用户发送消息是什么意思,但是要让它只在一个频道中工作,你应该从discord服务器复制频道ID,然后在代码比较
message.channel.ID==“你的频道ID”
,或者,也可以选择message.channel.name==“您的频道名称”
,将其设置为if语句,并且仅覆盖其中的perms。我将更新答案以包含此内容。该频道现在可以正常工作,但正如我之前所说的,如果其他用户发送消息,它将允许被静音的用户再次发送消息。我现在明白了,我已经复制了该问题。当我知道解决方案后,我会更新答案并发表评论。@BilalAhmed我已经修复了错误。我自己用2个用户测试了它,它运行正常。