Discord 聊天机器人更改频道 post 权限

Discord chat bot change channel post permissions

我目前正在为角色扮演酒吧编写一个不和谐的机器人。我希望它在我告诉它时关闭该栏(即,将 post 权限限制在我身上)。

代码如下:

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 后面放什么才能将默认聊天权限更改为无 posting?

您可以尝试像这样使用 .overwritePermissions,它会在 channel 中配置 Role 的权限,以不允许具有该角色的任何人发送消息:

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);
}

您只需确保拥有 Role 的人没有其他 Role 允许他们发送消息。