Javascript Discord聊天机器人更改频道发布权限
我目前正在为角色扮演酒吧编写一个discord机器人。当我告诉它时,我希望它关闭该栏(即仅限我发布权限) 代码如下:Javascript Discord聊天机器人更改频道发布权限,javascript,node.js,discord,Javascript,Node.js,Discord,我目前正在为角色扮演酒吧编写一个discord机器人。当我告诉它时,我希望它关闭该栏(即仅限我发布权限) 代码如下: const Discord = require("discord.js"); const bot = new Discord.Client(); bot.on("message", (message) => { switch (message.content) { case "Close down the bar for me":
const Discord = require("discord.js");
const bot = new Discord.Client();
bot.on("message", (message) => {
switch (message.content) {
case "Close down the bar for me":
if (message.author.discriminator == ) { // this isn't a typo i just haven't put it in for posting
message.postMessage("*Ushers people out, closes the cabinets, changes sign to closed, checks for stragglers, locks the doors, shuts the metal barriers, gets on motorbike and rides home*");
}
}
});
bot.login(''); // the token is meant to be here, I'm just not putting it on the internet!
我应该在message.postMessage之后放置什么才能将默认聊天权限更改为禁止发布?您可以尝试这样使用,它将频道中角色的权限配置为不允许任何具有该角色的人发送消息:
function closeDownChannel(message) {
let channel = message.channel;
let roles = message.guild.roles; // collection
// find specific role - enter name of a role you create here
let testRole = roles.cache.find(r => r.id === 'role_id_here');
// overwrites 'SEND_MESSAGES' role, only on this specific channel
channel.overwritePermissions(
testRole,
{ 'SEND_MESSAGES': false },
// optional 'reason' for permission overwrite
'closing up shop'
)
// handle responses / errors
.then(console.log)
.catch(console.log);
}
你只需确保拥有角色的人
没有其他角色
允许他们发送消息。你到底想做什么,你会遇到什么错误?正如我所说,我希望能够更改聊天的权限,这样就没有人可以在上面发表文章了。我没有任何错误,因为我不知道从哪里开始。你是说channel.sendMessage
?