javascript - Discord chat bot change channel post permissions - Stack Overflow

I'm currently writing a discord bot for a role-play bar. I want it to close down the bar (i.e. res

I'm currently writing a discord bot for a role-play bar. I want it to close down the bar (i.e. restrict post permissions to just me) when I tell it to.

Here's the code:

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!

what should I put after the message.postMessage to change the default chat permissions to no posting?

I'm currently writing a discord bot for a role-play bar. I want it to close down the bar (i.e. restrict post permissions to just me) when I tell it to.

Here's the code:

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!

what should I put after the message.postMessage to change the default chat permissions to no posting?

Share Improve this question asked Apr 20, 2017 at 10:35 JianZenJianZen 2271 gold badge5 silver badges13 bronze badges 3
  • What exactly you want to do, what is the error you are getting? – abdulbari Commented Apr 20, 2017 at 10:40
  • As i said, I want to be able to change the permissions of the chat so noone can post on it. I haven't got any errors because I don't know where to start. – JianZen Commented Apr 20, 2017 at 10:42
  • 1 Don't you mean channel.sendMessage ? – Wright Commented Apr 20, 2017 at 11:50
Add a ment  | 

1 Answer 1

Reset to default 2

You can try using .overwritePermissions like this, which configures the permissions of a Role in a channel to not allow anyone with that role to send messages:

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

You just have to make sure the people with that Role don't also have other Roles allowing them to send messages.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744683444a4587771.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论