admin管理员组文章数量:1391981
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
1 Answer
Reset to default 2You 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 Role
s allowing them to send messages.
本文标签: javascriptDiscord chat bot change channel post permissionsStack Overflow
版权声明:本文标题:javascript - Discord chat bot change channel post permissions - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744683443a2619554.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论