test(Discord) Added test logs to discord and start of discord chat bot

This commit is contained in:
2022-04-28 12:56:49 -04:00
parent 156339786c
commit b65dae0884
25 changed files with 6277 additions and 181 deletions
+2
View File
@@ -0,0 +1,2 @@
node_modules
.env
+1
View File
@@ -0,0 +1 @@
worker: node index.js
+11
View File
@@ -0,0 +1,11 @@
# Discord bot example
Read this [article](https://medium.freecodecamp.org/how-to-create-a-discord-bot-under-15-minutes-fb2fd0083844) to fully understand what this is about 😃
## Getting started
1. Clone this repository
2. Run `npm install`
3. Grab a token on [Discord's developer portal](https://discordapp.com/developers/applications)
4. Create a `.env` file and add a `BOT_TOKEN` environmental variable whose value is the token above.
5. Run `npm run dev`
+18
View File
@@ -0,0 +1,18 @@
module.exports = message => {
const member = message.mentions.members.first();
if (!member) {
return message.reply(
`Who are you trying to kick? You must mention a user.`
);
}
if (!member.kickable) {
return message.reply(`I can't kick this user. Sorry!`);
}
return member
.kick()
.then(() => message.reply(`${member.user.tag} was kicked.`))
.catch(error => message.reply(`Sorry, an error occured.`));
};
+5
View File
@@ -0,0 +1,5 @@
module.exports = (client, member) => {
member.send(
`Welcome on the server! Please be aware that we won't tolerate troll, spam or harassment. Have fun 😀`
);
};
+7
View File
@@ -0,0 +1,7 @@
const kick = require("../commands/kick");
module.exports = (client, message) => {
if (message.content.startsWith("!kick")) {
return kick(message);
}
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = client => {
console.log(`Logged in as ${client.user.tag}!`);
};
+17
View File
@@ -0,0 +1,17 @@
require("dotenv").config();
const Discord = require("discord.js");
const fs = require("fs");
const client = new Discord.Client();
fs.readdir("./events/", (err, files) => {
files.forEach(file => {
const eventHandler = require(`./events/${file}`);
const eventName = file.split(".")[0];
client.on(eventName, (...args) => eventHandler(client, ...args));
});
});
client.login(process.env.BOT_TOKEN);
client.channels.find(x=> x.id === "969297543538311248");
+5938
View File
File diff suppressed because it is too large Load Diff
+20
View File
@@ -0,0 +1,20 @@
{
"name": "discord-bot",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js",
"dev": "nodemon index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"discord.js": "^11.4.2",
"dotenv": "^7.0.0"
},
"devDependencies": {
"nodemon": "^1.18.11"
}
}