mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-12 09:33:32 +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);
|
||||
Reference in New Issue
Block a user