10 Commits

20 changed files with 372 additions and 49 deletions

View File

@@ -9,3 +9,11 @@ you think im going to put any effort in this shit?
i didnt even remove the text behind the emoji i just copied it from my google search
feel free to copy and make it 10 times better
# updates:
- switch to master was succesfull
- changed main branch from "main" to "master" ; git client didnt like main anymore... the wonderworld of git...
- will update this readme file for others who googled how to make an discord bot.

View File

@@ -1,6 +1,6 @@
/*
* This is for your reference. this is how we dit it first
* This is for your reference. this is how we did it first
* check commit 459446526602d35af9cec596b552cddeeac4c992
*
* we now use a "handler" and keep it organised with command files

View File

@@ -7,36 +7,25 @@ var fs = require('fs');
zoizbot.commands = new Discord.Collection();
console.log("==============================================");
console.log(`starting zoizbot...`);
console.log(" ==============================================");
console.log(` starting zoizbot...`);
eval(fs.readFileSync('./bootscreen.js') + ''); // please delete this, using readFileSync 1 time was bad enough. But I didnt want ascii art in my main file ;)
console.log(`loading configuration file...`)
console.log(` loading configuration file...`)
const config = require("./conf.json"); // de conf ophalen die we net gemaakt hadden / picking up the config file we made
console.log(`configuration loaded!`) // should make an catch error to debug conf file but whatever
console.log("==============================================");
console.log(`loading the commandhandler...`)
console.log(` configuration loaded!`) // should make an catch error to debug conf file but whatever
console.log(" ==============================================");
console.log(` loading the commandhandler...`)
eval(fs.readFileSync('./commandhandler.js') + '');
console.log(`commandhandler loaded!`)
console.log("==============================================");
console.log(`loading command-files...`)
console.log(` commandhandler loaded!`)
console.log(" ==============================================");
console.log(" ")
console.log(` loading command-files...`)
console.log(" ")
fs.readdir(`./commands/`, (err, files) => {
if (err) return console.error(err);
files.forEach(file => {
if (!file.endsWith(".js")) return; // only load js files. no garbage collection
let props = require(`./commands/${file}`); // get the command name from the file.js
let commandName = file.split(".")[0];
console.log(`attempting to load command ${commandName}`); // adding everything to the collection
zoizbot.commands.set(commandName, props);
});
console.log(`all commands loaded!`);
console.log("==============================================");
});
eval(fs.readFileSync('./commandloader.js') + ''); // Loading from command folders. easy mode :)
zoizbot.login(config.token); //reading the "token" from the const config = conf.json btw the one you see is invalid now
zoizbot.login(config.token).catch(console.error); //reading the "token" from the const config = conf.json btw the one you see is invalid now

View File

@@ -1,15 +1,15 @@
// bad practice please remove this file and the fileReadSync function
console.log("==============================================");
console.log(" ,--, ");
console.log(" ,----, ,---. ,--.'| ,----, ");
console.log(" .' .`| ' ,'\ | |, .' .`| ");
console.log(" .' .' .' / / |`--'_ .' .' .' ");
console.log(",---, ' ./ . ; ,. :,' ,'| ,---, ' ./ ");
console.log("; | .' / ' | |: :' | | ; | .' / ");
console.log("`---' / ;--,' | .; :| | : `---' / ;--, ");
console.log(" / / / .`|| : |' : |__ / / / .`| ");
console.log("./__; .' \ \ / | | '.'|./__; .' ");
console.log("; | .' `----' ; : ;; | .' ");
console.log("`---' | , / `---' ");
console.log(" ---`-' ");
console.log("==============================================");
console.log(" ==============================================");
console.log(" ,--, ");
console.log(" ,----, ,---. ,--.'| ,----, ");
console.log(" .' .`| ' ,'\ | |, .' .`| ");
console.log(" .' .' .' / / | `--'_ .' .' .' ");
console.log(" ,---, ' ./ . ; ,. : ,' ,'| ,---, ' ./ ");
console.log(" ; | .' / ' | |: : ' | | ; | .' / ");
console.log(" `---' / ;--,' | .; : | | : `---' / ;--, ");
console.log(" / / / .`|| : | ' : | / / / .`| ");
console.log(" ./__; .' \ \ / | | | /__; .' ");
console.log(" ; | .' `----' ; : | ;; | .' ");
console.log(" `---' | , : `---' ");
console.log(" ---` ");
console.log(" ==============================================");

View File

@@ -1,16 +1,17 @@
zoizbot.on("ready", () => {
zoizbot.user.setActivity(config.activity); // change this to whatever you want (in conf.json).
console.log(`Zoizbot has started, and is serving ${zoizbot.users.cache.size} users, in ${zoizbot.guilds.cache.size} guilds.`); // you can display anything you want here, all the functions are available in de documentation from discord.js
console.log("==================LISTENING===================");
console.log(` Zoizbot is listening, `); // you can display anything you want here, all the functions are available in de documentation from discord.js
console.log(` and is currently serving ${ zoizbot.users.cache.size } users, in ${ zoizbot.guilds.cache.size } guilds.`)
console.log(" ==================LISTENING===================");
});
zoizbot.on("guildJoin", guild => {
console.log(`I have joined ${guild.name}, I will be serving ${guild.memberCount} members!`); // Join server message in the console
message.channel.send(`Hello ${guild.name} thank you for having me!`);
console.log(` I have joined ${guild.name}, I will be serving ${guild.memberCount} members!`); // Join server message in the console
message.channel.send(` Hello ${guild.name}, thank you for having me!`);
});
zoizbot.on("guildLeave", guild => {
console.log(`Adios! i will be leaving: ${guild.name}, it was fun while it lasted!`); //letting you know he be headin out
console.log(` Adios! i will be leaving: ${guild.name}, it was fun while it lasted!`); //letting you know he be headin out
});
zoizbot.on("message", async message => {
@@ -22,4 +23,4 @@ zoizbot.on("message", async message => {
if (!cmd) return; //if the command doesnt exist gracefully return
cmd.run(zoizbot, message, args); // and fire!
});
});

69
zoizbot/commandloader.js Normal file
View File

@@ -0,0 +1,69 @@
var loaded = 0
fs.readdir (`./commands/`, (err, files) => {
if (err) return console.error(err);
files.forEach(file => {
if (!file.endsWith(".js")) return; // only load js files. no garbage collection
let props = require(`./commands/${file}`); // get the command name from the file.js
let commandName = file.split(".")[0];
console.log(` attempting to load command: ${commandName}`); // adding everything to the collection
zoizbot.commands.set(commandName, props);
});
loaded++; // beginners trick to check if all the folder-commands where loaded // i really dont know what im doing here hahahaha //edit2 i made it even worse :(
if (loaded == 4) { // this is the funniest shit i have ever done. pure for asthetics. please change this to a different way
console.log(" ")
console.log(` all commands loaded!`);
console.log(" ")
console.log(" ==============================================");
}
});
fs.readdir (`./commands/fun/`, (err, files) => {
if (err) return console.error(err);
files.forEach(file => {
if (!file.endsWith(".js")) return;
let props = require(`./commands/fun/${file}`);
let commandName = file.split(".")[0];
console.log(` attempting to load command: ${commandName}`);
zoizbot.commands.set(commandName, props);
});
loaded++;
if (loaded == 4) {
console.log(" ")
console.log(` all commands loaded!`);
console.log(" ")
console.log(" ==============================================");
}
});
fs.readdir(`./commands/general/`, (err, files) => {
if (err) return console.error(err);
files.forEach(file => {
if (!file.endsWith(".js")) return;
let props = require(`./commands/general/${file}`);
let commandName = file.split(".")[0];
console.log(` attempting to load command: ${commandName}`);
zoizbot.commands.set(commandName, props);
});
loaded++;
if (loaded == 4) {
console.log(" ")
console.log(` all commands loaded!`);
console.log(" ")
console.log(" ==============================================");
}
});
fs.readdir(`./commands/moderation/`, (err, files) => { //copy paste for different folders works fine. dirty fix no.394 haha
if (err) return console.error(err);
files.forEach(file => {
if (!file.endsWith(".js")) return;
let props = require(`./commands/moderation/${file}`);
let commandName = file.split(".")[0];
console.log(` attempting to load command: ${commandName}`);
zoizbot.commands.set(commandName, props);
});
loaded++;
if (loaded == 4) {
console.log(" ")
console.log(` all commands loaded!`);
console.log(" ")
console.log(" ==============================================");
}
});

View File

@@ -0,0 +1,11 @@
{
"method": "GET",
"hostname": "joke3.p.rapidapi.com",
"port": null,
"path": "/v1/joke?nsfw=false",
"headers": {
"x-rapidapi-host": "joke3.p.rapidapi.com",
"x-rapidapi-key": "589805bc00msh85fd454fda665e8p11475cjsnacbc1293e0a5",
"useQueryString": true
}
}

View File

@@ -0,0 +1,47 @@
exports.run = async (zoizbot, message, args) => {
const Discord = require('discord.js'); // for some reason the jokeembed build needs discord.js defined again. whatever
var http = require("https");
const jokeconfig = require("./apiconfigs/joke.json"); // keep the code clean and save the variables in a config file
const jokeloader = new Discord.MessageEmbed() // a litle feedback for if the api is slow, or the server's connection. with a nice embed for the loading joke message
.setColor('#0099ff')
.setDescription("Requesting a funny joke...")
const joke = await message.channel.send(jokeloader); // send the loading embed
var req = http.request(jokeconfig, function (res) { // requesting the "joke" API and pleuring it in a chunk
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function () {
const body = Buffer.concat(chunks);
//console.log(body.toString()); // just a debug to see if the api be spitting the joke. Only logging body would lead to unreadable bytes, so we use toString. Simple and easy!
const jokebody = (JSON.parse(body.toString())); // i cant belive a JSON.parse worked actually // i like saving every thing in a const, i wish that worked with my parents marriage...
//message.channel.send(jokebody.content); // Check if our joke JSON parses correctly by only displaying the "content".
// the jokes arent that funny so lets make it goooooodlooking with a simple embed we also used in embeddedkick example
const jokeembed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle('Joke API')
.setURL('https://rapidapi.com/LemmoTresto/api/joke3/details')
.setDescription(jokebody.content)
.addFields(
{ name: 'Joke upvotes', value: jokebody.upvotes, inline: true },
{ name: 'Joke downvotes', value: jokebody.downvotes, inline: true },
)
.setTimestamp()
.setFooter(`joke API example - Joke id: ${jokebody.id}`);
joke.edit(jokeembed); // finally edit the jokes content
});
});
req.end();
}

View File

@@ -0,0 +1,20 @@
/*
* a command that reloads the command you have edited to memory
* so you dont have to reboot the bot
* good for testing, not so much for production
* ive added the permission test, to make sure not everybody spams reload
*/
exports.run = (zoizbot, message, args) => {
if (!message.member.hasPermission("ADMINISTRATOR"))
return message.reply("Sorry, you don't have permissions to use this!");
if (!args || args.length < 1) return message.reply("Please provide the command name to reload.");
const commandName = args[0];
if (!zoizbot.commands.has(commandName)) {
return message.reply("That command does not exist");
}
delete require.cache[require.resolve(`./${commandName}.js`)];
zoizbot.commands.delete(commandName);
const props = require(`./${commandName}.js`);
zoizbot.commands.set(commandName, props);
message.reply(`The command ${commandName} has been reloaded`);
};

View File

@@ -0,0 +1,20 @@
/*
* a command that reloads the command you have edited to memory
* so you dont have to reboot the bot
* good for testing, not so much for production
* ive added the permission test, to make sure not everybody spams reload
*/
exports.run = (zoizbot, message, args) => {
if (!message.member.hasPermission("ADMINISTRATOR"))
return message.reply("Sorry, you don't have permissions to use this!");
if (!args || args.length < 1) return message.reply("Please provide the command name to reload.");
const commandName = args[0];
if (!zoizbot.commands.has(commandName)) {
return message.reply("That command does not exist");
}
delete require.cache[require.resolve(`./${commandName}.js`)];
zoizbot.commands.delete(commandName);
const props = require(`./${commandName}.js`);
zoizbot.commands.set(commandName, props);
message.reply(`The command ${commandName} has been reloaded`);
};

View File

@@ -0,0 +1,22 @@
//simple add role to user command.
// im done. im not going to finish it, Adios see you in another project
exports.run = async (zoizbot, message, args) => {
if (!message.member.hasPermission("MANAGE_ROLES"))
return message.reply("Sorry, you don't have permissions to use this!")
let member = message.mentions.members.first();
let role = message.mentions.roles.first();
if (!member)
return message.reply("Please mention a valid member of this server");
if (!role || role.length < 1)
return message.reply("Please provide the role you want to add.");
member.roles.add(role).catch(console.error);
// TODO: catch the errors and reply . cant be bothered at the moment
//member.roles.remove(role).catch(console.error); //remove
}

View File

@@ -0,0 +1,18 @@
exports.run = async (zoizbot, message, args) => {
if (!message.member.hasPermission("BAN_MEMBERS"))
return message.reply("Sorry, you don't have permissions to use this!")
let member = message.guild.member(message.mentions.users.first()) || message.mentions.members.first(args[0])
if (!member)
return message.reply("Please mention a valid member of this server")
if (message.member.hasPermission("BAN_MEMBERS"))
return message.reply("I cannot ban this user! Invalid Permissions")
let banReason = args.join(" ").slice(22);
if (!banReason) {
banReason = "No reason provided"
}
member.ban({ reason: banReason })
return message.reply(`${member.user.tag} has been banned by ${message.author.tag} because: ${banReason}`)
}

View File

@@ -0,0 +1,18 @@
exports.run = async (zoizbot, message, args) => {
if (!message.member.hasPermission("KICK_MEMBERS"))
return message.reply("Sorry, you don't have permissions to use this!");
let member = message.guild.member(message.mentions.users.first()) || message.mentions.members.first(args[0])
if (!member)
return message.reply("Please mention a valid member of this server");
if (!member.kickable)
return message.reply("I cannot kick this user! Do they have a higher role? Do I have kick permissions?");
let KickReason = args.slice(1).join(' ');
if (!KickReason) KickReason = "No reason provided";
await member.kick(KickReason)
.catch(error => message.reply(`Sorry ${message.author} I couldn't kick because of : ${error}`)); // now an adios moment
message.reply({ embed: { "title": "Kicked", "color": 15746887, "fields": [{ "name": "Information", "value": `${member.user.tag} has been kicked by ${message.author.tag}.\nReason: ${KickReason}` }] } }); // sebastiaan created this one, he likes the embedded stuff
}

View File

@@ -0,0 +1,19 @@
exports.run = async (zoizbot, message, args) => {
if (!message.member.hasPermission("KICK_MEMBERS"))
return message.reply("Sorry, you don't have permissions to use this!");
let member = message.guild.member(message.mentions.users.first()) || message.mentions.members.first(args[0])
if (!member)
return message.reply("Please mention a valid member of this server");
if (!member.kickable)
return message.reply("I cannot kick this user! Do they have a higher role? Do I have kick permissions?");
let KickReason = args.slice(1).join(' '); // joining the sliced the arguments
if (!KickReason) KickReason = "No reason provided";
await member.kick(KickReason)
.catch(error => message.reply(`Sorry ${message.author} I couldn't kick because of : ${error}`)); // now an adios moment
message.reply(`${member.user.tag} has been kicked by ${message.author.tag} because: ${KickReason}`);
}

View File

@@ -0,0 +1,20 @@
/*
* a command that reloads the command you have edited to memory
* so you dont have to reboot the bot
* good for testing, not so much for production
* ive added the permission test, to make sure not everybody spams reload
*/
exports.run = (zoizbot, message, args) => {
if (!message.member.hasPermission("ADMINISTRATOR"))
return message.reply("Sorry, you don't have permissions to use this!");
if (!args || args.length < 1) return message.reply("Please provide the command name to reload.");
const commandName = args[0];
if (!zoizbot.commands.has(commandName)) {
return message.reply("That command does not exist");
}
delete require.cache[require.resolve(`./${commandName}.js`)];
zoizbot.commands.delete(commandName);
const props = require(`./${commandName}.js`);
zoizbot.commands.set(commandName, props);
message.reply(`The command ${commandName} has been reloaded`);
};

View File

@@ -0,0 +1,29 @@
/*
* a command that reloads the command you have edited to memory
* so you dont have to reboot the bot
* good for testing, not so much for production
* ive added the permission test, to make sure not everybody spams reload
*/
exports.run = (zoizbot, message, args) => {
const config = require("../conf.json");
message.channel.send({ embed: { "title": "Reload Tool", "color": 15746887, "fields": [{ "name": "Reload command file Syntax", "value": ` \n${config.prefix}reloadmoderation "command"\n${config.prefix}reloadgeneral "command" \n${config.prefix}reloadfun "command"` }] } });
/*
* uncomment if you have commandfiles in de /commands folder
* i did it the easy way. so should you haha
*
if (!message.member.hasPermission("ADMINISTRATOR"))
return message.reply("Sorry, you don't have permissions to use this!");
if (!args || args.length < 1) return message.reply("Please provide the command name to reload.");
const commandName = args[0];
if (!zoizbot.commands.has(commandName)) {
return message.reply("That command does not exist");
}
delete require.cache[require.resolve(`./${commandName}.js`)];
zoizbot.commands.delete(commandName);
const props = require(`./${commandName}.js`);
zoizbot.commands.set(commandName, props);
message.reply(`The command ${commandName} has been reloaded`);
*/
};

View File

@@ -1,4 +1,5 @@
{
"token": "null",
"prefix": ">"
"token": "",
"prefix": ">",
"activity": "Ask me something with >"
}

View File

@@ -42,10 +42,37 @@
<Content Include="commandhandler.js">
<SubType>Code</SubType>
</Content>
<Content Include="commands\hello.js">
<Content Include="commandloader.js">
<SubType>Code</SubType>
</Content>
<Content Include="commands\ping.js">
<Content Include="commands\fun\apiconfigs\joke.json">
<SubType>Code</SubType>
</Content>
<Content Include="commands\fun\joke.js">
<SubType>Code</SubType>
</Content>
<Content Include="commands\fun\reloadfun.js" />
<Content Include="commands\general\hello.js">
<SubType>Code</SubType>
</Content>
<Content Include="commands\general\ping.js">
<SubType>Code</SubType>
</Content>
<Content Include="commands\general\reloadgeneral.js" />
<Content Include="commands\moderation\addrole.js">
<SubType>Code</SubType>
</Content>
<Content Include="commands\moderation\ban.js">
<SubType>Code</SubType>
</Content>
<Content Include="commands\moderation\embeddedkick.js">
<SubType>Code</SubType>
</Content>
<Content Include="commands\moderation\kick.js">
<SubType>Code</SubType>
</Content>
<Content Include="commands\moderation\reloadmoderation.js" />
<Content Include="commands\reload.js">
<SubType>Code</SubType>
</Content>
<Content Include="Legacy Commands\examples.js" />
@@ -54,6 +81,10 @@
</ItemGroup>
<ItemGroup>
<Folder Include="commands\" />
<Folder Include="commands\fun\apiconfigs\" />
<Folder Include="commands\general\" />
<Folder Include="commands\moderation\" />
<Folder Include="commands\fun\" />
<Folder Include="Legacy Commands\" />
</ItemGroup>
<!-- Do not delete the following Import Project. While this appears to do nothing it is a marker for setting TypeScript properties before our import that depends on them. -->