Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
132
rated 0 times [  134] [ 2]  / answers: 1 / hits: 15510  / 7 Years ago, thu, april 20, 2017, 12:00:00

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?


More From » node.js

 Answers
14

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.


[#58078] Tuesday, April 18, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ariel

Total Points: 523
Total Questions: 111
Total Answers: 100

Location: Anguilla
Member since Sun, Jan 29, 2023
1 Year ago
;