【问题标题】:Discord chat bot change channel post permissionsDiscord 聊天机器人更改频道帖子权限
【发布时间】:2021-02-23 04:49:24
【问题描述】:

我目前正在为角色扮演栏编写一个不和谐机器人。当我告诉它时,我希望它关闭栏(即将发布权限仅限于我)。

代码如下:

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 之后添加什么来将默认聊天权限更改为不发帖?

【问题讨论】:

  • 你到底想做什么,你得到什么错误?
  • 正如我所说,我希望能够更改聊天的权限,这样没有人可以在上面发帖。我没有任何错误,因为我不知道从哪里开始。
  • 你不是说channel.sendMessage吗?

标签: javascript node.js discord


【解决方案1】:

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

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 的人没有其他Roles 允许他们发送消息。

【讨论】:

    猜你喜欢
    • 2020-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-14
    • 1970-01-01
    • 2021-07-05
    相关资源
    最近更新 更多