mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-13 10:03:31 +01:00
* Update examples * Forgot to save send-files
This commit is contained in:
committed by
abalabahaha
parent
b9506d01ab
commit
8d64435def
@@ -1,87 +1,72 @@
|
||||
/*
|
||||
this bot is a permissions bot and is currently working
|
||||
with the experimental additions. Some functions may
|
||||
change in the future.
|
||||
*/
|
||||
|
||||
var Discord = require("../../");
|
||||
|
||||
// Get the email and password
|
||||
// Get the token
|
||||
var AuthDetails = require("../auth.json");
|
||||
|
||||
var bot = new Discord.Client();
|
||||
|
||||
bot.on("ready", function () {
|
||||
console.log("Ready to begin! Serving in " + bot.channels.length + " channels");
|
||||
console.log(`Ready to begin! Serving in ${bot.channels.length} channels`);
|
||||
});
|
||||
|
||||
bot.on("disconnected", function () {
|
||||
|
||||
console.log("Disconnected!");
|
||||
process.exit(1); //exit node.js with an error
|
||||
|
||||
});
|
||||
|
||||
bot.on("message", function (msg) {
|
||||
if (msg.content === "skype") {
|
||||
|
||||
|
||||
//stop the user from speaking in the channel:
|
||||
bot.overwritePermissions(msg.channel, msg.sender, {
|
||||
bot.overwritePermissions(msg.channel, msg.author, {
|
||||
sendMessages: false
|
||||
});
|
||||
|
||||
|
||||
// send a barely funny message ;)
|
||||
bot.reply(msg, "how dare you mention that!");
|
||||
bot.reply(msg, "How dare you mention that!");
|
||||
|
||||
}
|
||||
|
||||
if (msg.content === "discord") {
|
||||
|
||||
|
||||
var role = msg.server.roles.get("name", "good people");
|
||||
|
||||
// if the role doesn't exist, make it
|
||||
bot.createRoleIfNotExists(msg.channel.server, {
|
||||
name: "good people",
|
||||
color: Discord.Colors.BLUE, // colour of blue
|
||||
hoist: true // make a seperate category in the users list
|
||||
}).then(addUserToList).catch(console.log);
|
||||
|
||||
function addUserToList(role, alreadyExists) {
|
||||
console.log(arguments);
|
||||
bot.addMemberToRole(msg.sender, role);
|
||||
bot.reply(msg, "welcome to the good people! " + alreadyExists);
|
||||
|
||||
if (!role) {
|
||||
bot.createRole(msg.server, {
|
||||
name: "good people",
|
||||
color: "0000FF", // blue
|
||||
hoist: true // make a seperate category in the users list
|
||||
}).then(createdRole => {
|
||||
role = createdRole;
|
||||
}).catch(console.log);
|
||||
}
|
||||
|
||||
bot.addMemberToRole(msg.author, role);
|
||||
bot.reply(msg, "Welcome to the good people!");
|
||||
}
|
||||
|
||||
if (msg.content === "remove me") {
|
||||
// remove the user from the good people list, if it exists
|
||||
var found = false;
|
||||
var role = msg.server.roles.get("name", "good people");
|
||||
|
||||
for (var role of msg.channel.server.roles) {
|
||||
if (role.name === "good people") {
|
||||
found = role;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (role) { // if the role exists
|
||||
|
||||
if (found) {
|
||||
// if the role exists
|
||||
|
||||
if (msg.sender.hasRole(role)) {
|
||||
if (msg.author.hasRole(role)) {
|
||||
// remove the member from the role
|
||||
bot.removeMemberFromRole(msg.sender, role);
|
||||
bot.reply(msg, "removed!")
|
||||
bot.removeMemberFromRole(msg.author, role);
|
||||
bot.reply(msg, "Removed!")
|
||||
} else {
|
||||
bot.reply(msg, "you're not in the role!");
|
||||
bot.reply(msg, "You're not in the role!");
|
||||
}
|
||||
|
||||
} else {
|
||||
// role doesn't exist
|
||||
bot.reply(msg, "the role doesn't even exist!");
|
||||
bot.reply(msg, "The role doesn't even exist!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
bot.login(AuthDetails.email, AuthDetails.password);
|
||||
bot.loginWithToken(AuthDetails.token);
|
||||
@@ -18,58 +18,30 @@ bot.on("disconnected", function () {
|
||||
|
||||
console.log("Disconnected!");
|
||||
process.exit(1); //exit node.js with an error
|
||||
|
||||
|
||||
});
|
||||
|
||||
bot.on("message", function (msg) {
|
||||
|
||||
|
||||
// to use this example, you first have to send 'create role'
|
||||
// you can then change colors afterwards.
|
||||
|
||||
|
||||
if (msg.content === "create role") {
|
||||
// create the role and add the user to it
|
||||
|
||||
bot.createRoleIfNotExists(msg.channel.server, {
|
||||
|
||||
bot.createRole(msg.server, {
|
||||
name: "Custom Colors",
|
||||
hoist: true, // so it is visible in the members list
|
||||
}).then(function (permission) {
|
||||
// this is executed when the role has been created or exists
|
||||
|
||||
// adds the sender to the role
|
||||
bot.addMemberToRole(msg.sender, permission).then(function () {
|
||||
bot.reply(msg, "added you to the role!");
|
||||
});
|
||||
}).then(createdRole => { // this is executed when the role has been created
|
||||
|
||||
// adds the sernder to the role
|
||||
bot.addMemberToRole(msg.author, createdRole).then(() => {
|
||||
bot.reply(msg, "Added you to the role!");
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
if (msg.content.indexOf("preset color") === 0) {
|
||||
|
||||
// set the role to a preset color
|
||||
var colorName = msg.content.split(" ")[2];
|
||||
|
||||
// get the role by its name
|
||||
var role = msg.channel.server.getRole("name", "Custom Colors");
|
||||
|
||||
// if the color exists as a preset
|
||||
if (Discord.Color[colorName]) {
|
||||
|
||||
// update the role with the new color
|
||||
bot.updateRole(role, {
|
||||
color: Discord.Color[colorName]
|
||||
}).then(function (role) {
|
||||
// this executes if the change was correct
|
||||
bot.reply(msg, "done! using the color " + Discord.Color.toHex(role.color));
|
||||
});
|
||||
|
||||
} else {
|
||||
bot.reply(msg, "that color isn't a preset color!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (msg.content.indexOf("custom color") === 0) {
|
||||
else if (msg.content.startsWith("custom color")) {
|
||||
|
||||
// valid custom colors must follow the format of any of the following:
|
||||
/*
|
||||
@@ -79,27 +51,23 @@ bot.on("message", function (msg) {
|
||||
*/
|
||||
|
||||
var colorName = msg.content.split(" ")[2];
|
||||
|
||||
|
||||
// get the role by its name
|
||||
var role = msg.channel.server.getRole("name", "Custom Colors");
|
||||
var role = msg.server.roles.get("name", "Custom Colors");
|
||||
|
||||
// updates the role with the given color
|
||||
bot.updateRole(role, {
|
||||
color: colorName
|
||||
}).then(function (role) {
|
||||
|
||||
|
||||
// this executes if the change was successful
|
||||
bot.reply(msg, "done! using the color " + Discord.Color.toHex(role.color));
|
||||
|
||||
bot.reply(msg, "Done! Using the color " + colorName);
|
||||
}).catch(function (e) {
|
||||
|
||||
|
||||
// this executes if it wasn't successful
|
||||
bot.reply(msg, "an error occurred. Was that a valid hex/dec color?");
|
||||
|
||||
})
|
||||
|
||||
bot.reply(msg, "An error occurred. Was that a valid hex/dec color?");
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
bot.login(AuthDetails.email, AuthDetails.password);
|
||||
bot.loginWithToken(AuthDetails.token);
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
var Discord = require("../../");
|
||||
|
||||
Discord.patchStrings();
|
||||
|
||||
var AuthDetails = require("../auth.json");
|
||||
|
||||
var bot = new Discord.Client();
|
||||
@@ -13,38 +11,36 @@ bot.on("ready", () => {
|
||||
});
|
||||
|
||||
bot.on("message", (msg) => {
|
||||
|
||||
var user = msg.author;
|
||||
|
||||
if(msg.content === "can I tts?"){
|
||||
|
||||
var user = msg.sender;
|
||||
|
||||
|
||||
// get the evaluated permissions for a user in the channel they asked
|
||||
var permissions = msg.channel.permissionsOf(user);
|
||||
|
||||
if(permissions.sendTTSMessages){
|
||||
bot.reply(msg, "You " + "can".italic.bold + " send TTS messages.");
|
||||
}else{
|
||||
bot.reply(msg, "You " + "can't".italic.bold + " send TTS messages.");
|
||||
}
|
||||
|
||||
}else if(msg.content === "what are my full permissions?"){
|
||||
|
||||
var user = msg.sender;
|
||||
|
||||
|
||||
if(permissions.sendTTSMessages)
|
||||
bot.reply(msg, "You ***can*** send TTS messages.");
|
||||
|
||||
else
|
||||
bot.reply(msg, "You ***can't*** send TTS messages.");
|
||||
|
||||
|
||||
} else if(msg.content === "what are my full permissions?") {
|
||||
|
||||
// get the serialised permissions of the user
|
||||
var permissions = msg.channel.permissionsOf(user).serialise();
|
||||
|
||||
|
||||
// if you want to stringify permissions, they need to be serialised first.
|
||||
|
||||
|
||||
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
|
||||
http://discordjs.readthedocs.io/en/indev/docs_permissionconstants.html
|
||||
*/
|
||||
|
||||
|
||||
})
|
||||
|
||||
bot.login(AuthDetails.email, AuthDetails.password);
|
||||
bot.loginWithToken(AuthDetails.token);
|
||||
Reference in New Issue
Block a user