Discord chat bot更改频道发布权限

时间:2017-04-20 10:35:33

标签: javascript node.js 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":
            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之后将默认聊天权限更改为无帖子?

2 个答案:

答案 0 :(得分:1)

您可以尝试使用这样的.overwritePermissions,它会Role channelfunction 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.find('name', '<name of role>'); // 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); } 的权限,不允许具有该角色的任何人发送消息:

Role

您必须确保拥有该Role的用户不允许其他talentCode.Length()个人发送消息。

答案 1 :(得分:-1)

从我在他们的文档中看到的,它应该是message.sendMessage而不是postMessage。并且该方法还具有参数&#34; channel,content,options,callback&#34;。

更多信息可在以下网址找到:https://discordjs.readthedocs.io/en/latest/docs_client.html