mirror of
https://github.com/danbulant/discord.js
synced 2026-07-06 11:40:41 +00:00
New permissions example
This commit is contained in:
parent
d08e802083
commit
2c9c961b8e
3 changed files with 54 additions and 42 deletions
5
examples/jsconfig.json
Normal file
5
examples/jsconfig.json
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "ES6"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -4,10 +4,10 @@
|
||||||
change in the future.
|
change in the future.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var Discord = require("../");
|
var Discord = require("../../");
|
||||||
|
|
||||||
// Get the email and password
|
// Get the email and password
|
||||||
var AuthDetails = require("./auth.json");
|
var AuthDetails = require("../auth.json");
|
||||||
|
|
||||||
var bot = new Discord.Client();
|
var bot = new Discord.Client();
|
||||||
|
|
||||||
|
|
@ -1,41 +1,48 @@
|
||||||
/* this bot will see if a user can send TTS messages */
|
/* this bot will see if a user can send TTS messages */
|
||||||
|
|
||||||
var Discord = require("../");
|
var Discord = require("../../");
|
||||||
|
|
||||||
var AuthDetails = require("./auth.json");
|
var AuthDetails = require("../auth.json");
|
||||||
|
|
||||||
var bot = new Discord.Client();
|
var bot = new Discord.Client();
|
||||||
|
|
||||||
bot.on("ready", () => {
|
bot.on("ready", () => {
|
||||||
console.log("Ready to begin!");
|
console.log("Ready to begin!");
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.on("message", (msg) => {
|
bot.on("message", (msg) => {
|
||||||
|
|
||||||
if(msg.content === "can I tts?"){
|
if(msg.content === "can I tts?"){
|
||||||
|
|
||||||
var user = msg.sender;
|
var user = msg.sender;
|
||||||
|
|
||||||
// get the evaluated permissions for a user in the channel they asked
|
// get the evaluated permissions for a user in the channel they asked
|
||||||
var permissions = msg.channel.permissionsOf(user);
|
var permissions = msg.channel.permissionsOf(user);
|
||||||
|
|
||||||
if(permissions.sendTTSMessages){
|
if(permissions.sendTTSMessages){
|
||||||
|
bot.reply(msg, "You *can* send TTS messages.");
|
||||||
bot.reply(msg, "You *can* send TTS messages.");
|
}else{
|
||||||
|
bot.reply(msg, "You *can't* send TTS messages.");
|
||||||
}else{
|
}
|
||||||
|
|
||||||
bot.reply(msg, "You *can't* send TTS messages.");
|
}else if(msg.content === "what are my full permissions?"){
|
||||||
|
|
||||||
}
|
var user = msg.sender;
|
||||||
|
|
||||||
}
|
// get the serialised permissions of the user
|
||||||
|
var permissions = msg.channel.permissionsOf(user).serialise();
|
||||||
/*
|
|
||||||
for a list of more permissions, go to
|
// if you want to stringify permissions, they need to be serialised first.
|
||||||
https://github.com/hydrabolt/discord.js/blob/master/src/EvaluatedPermissions.js
|
|
||||||
*/
|
bot.reply(msg, JSON.stringify(permissions, null, 4).replace(/true/g, "**true**"));
|
||||||
|
|
||||||
})
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
for a list of more permissions, go to
|
||||||
|
https://github.com/hydrabolt/discord.js/blob/master/src/EvaluatedPermissions.js
|
||||||
|
*/
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
bot.login(AuthDetails.email, AuthDetails.password);
|
bot.login(AuthDetails.email, AuthDetails.password);
|
||||||
Loading…
Reference in a new issue