Skip to content

Commit

Permalink
Merge pull request #17 from mrranger/main
Browse files Browse the repository at this point in the history
The project has been updated to Discord.js 14.16.2
  • Loading branch information
LachlanDev authored Sep 25, 2024
2 parents 610a5d1 + d48fd31 commit c303813
Show file tree
Hide file tree
Showing 23 changed files with 3,095 additions and 1,602 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Logs
/src/config/config.json


logs
*.log
npm-debug.log*
Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,19 @@ Rename ``config.default.json`` to ``config.json`` and open up the file, this can
{
"clientID":"BOTclientID",
"clientSecret":"BOTclientSecret",
"callbackURL":"BOTcallbackURL",
"callbackURL":"http://localhost:1337/login/api",
"Admin":["userAdminID"],
"token":"BOTtoken",
"prefix":"-",
"port":"3000"
}

```

Redirects
You must specify at least one URI for authentication to work. If you pass a URI in an OAuth request, it must exactly match one of the URIs you enter here.
http://localhost:1337/login/api

Make sure to enable both "Privileged Gateway Intents" on the [**Discord Developer Dashboard**](https://discord.com/developers). This is to fix errors with "Kick / Ban" Commands!

#### 📡 Starting the application
Expand All @@ -61,7 +67,7 @@ A list of some of the features that are included in Discord BOT Dashboard V2
If you would like to contribute to the project please open a PR (Pull Request) clearly showing your changes.

## 🔒 Requirements
* [Node.JS](https://nodejs.org/en/) (v12.3.1 or later)
* [Node.JS](https://nodejs.org/en/) (Node.js v20.16.0)

## 📞 Issues
If you have any issues feel free to open an issue or join the [Discord Server.](https://discord.com/invite/w7B5nKB)
Expand Down
8 changes: 4 additions & 4 deletions docs/docs/installation/basic.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ Rename ``config.default.json`` to ``config.json`` and open up the file, this can
{
"clientID":"BOTclientID",
"clientSecret":"BOTclientSecret",
"callbackURL":"BOTcallbackURL",
"callbackURL":"http://localhost:1337/login/api",
"Admin":["userAdminID"],
"token":"BOTtoken",
"prefix":"-",
"port":"3000"
"port":"1337"
}
```

* **``clientID``** - This is the Client ID for your BOT, this can be found in the [Discord Developer Portal](https://discord.com/developers) or in the Discord Client.
* **``clientSecret``** - This is the Client Secret for your BOT, this can be ONLY be found in the [Discord Developer Portal](https://discord.com/developers)
* **``callbackURL``** - Head over to OAuth2 and create a redirect link. Please use: ``http://localhost:3000/login/api`` Can change ``localhost`` for the IP of your system.
* **``callbackURL``** - Head over to OAuth2 and create a redirect link. Please use: ``http://localhost:1337/login/api`` Can change ``localhost`` for the IP of your system.

<img src="/assets/images/example_dbp.jpeg">

Expand All @@ -44,7 +44,7 @@ Open up the root directory and run the following command.
```bash
node index.js
```
You should now be able to access the dashboard at <a href="http://localhost:3000">http://localhost:3000</a> or the port you chose to use.
You should now be able to access the dashboard at <a href="http://localhost:1337">http://localhost:1337</a> or the port you chose to use.
</br>

If you ran into any errors or need any further help feel free to ask in the [Discord Server](https://discord.com/invite/w7B5nKB)
92 changes: 74 additions & 18 deletions src/bot.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,41 @@
const Discord = require("discord.js");
const Enmap = require("enmap");
const fs = require("fs");
json = require('json-update');
const chalk = require('chalk');
const commands = require('./commands/index');

const client = new Discord.Client();
const config = require('./config/config.json')
const settings = require('./config/settings.json')
const { GatewayIntentBits } = require('discord.js');

const client = new Discord.Client({
intents: [
GatewayIntentBits.Guilds, // Access to guilds (servers)
GatewayIntentBits.GuildMembers, // Access to guild members
GatewayIntentBits.GuildBans, // Access to user bans
GatewayIntentBits.GuildEmojisAndStickers, // Access to emojis and stickers
GatewayIntentBits.GuildIntegrations, // Access to integrations
GatewayIntentBits.GuildWebhooks, // Access to webhooks
GatewayIntentBits.GuildInvites, // Access to invitations
GatewayIntentBits.GuildVoiceStates, // Access to voice channels and user states
GatewayIntentBits.GuildPresences, // Access to presence statuses (online/offline)
GatewayIntentBits.GuildMessages, // Access to guild messages
GatewayIntentBits.GuildMessageReactions, // Access to guild message reactions
GatewayIntentBits.GuildMessageTyping, // Access to typing indicators
GatewayIntentBits.DirectMessages, // Access to direct messages (Direct Messages)
GatewayIntentBits.DirectMessageReactions, // Access to direct message reactions
GatewayIntentBits.DirectMessageTyping, // Access to typing indicators in direct messages
GatewayIntentBits.MessageContent, // Access to message content
GatewayIntentBits.GuildScheduledEvents, // Access to scheduled guild events
GatewayIntentBits.AutoModerationConfiguration, // Access to automatic moderation configuration
GatewayIntentBits.AutoModerationExecution // Access to automatic moderation rules execution moderation
]
});

const config = require('./config/config.json');
const settings = require('./config/settings.json');
client.commands = new Enmap();
chalk = require('chalk');
client.config = config;

// Loading events
fs.readdir("./events/", (err, files) => {
if (err) return console.error(err);
files.forEach(file => {
Expand All @@ -19,26 +45,56 @@ fs.readdir("./events/", (err, files) => {
});
});

client.commands = new Enmap();
// Loading commands
Object.keys(commands).forEach(commandName => {
let props = commands[commandName];
if (settings.includes(commandName)) return;
console.log(chalk.green(`[+] Loaded command: ${commandName}`));
console.log(`Loading command from ${__filename}`);


fs.readdir("./commands/", (err, files) => {
console.log(chalk.red('Loading Commands...'))
if (err) return console.error(err);
files.forEach(file => {
if (!file.endsWith(".js")) return;
let props = require(`./commands/${file}`);
let commandName = file.split(".")[0];
if (settings.includes(commandName)) return;
console.log(chalk.green(`[+] ${commandName}`));
client.commands.set(commandName, props);
});
try {
client.commands.set(commandName, props);
} catch (error) {
console.error(`Error loading command ${commandName}: ${error}`);
}
});

// Command processing
client.on('messageCreate', message => {
if (message.author.bot) return; // Ignore the bots
if (!message.content.startsWith(config.prefix)) return; // Prefix check

const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
const commandName = args.shift().toLowerCase();

const command = client.commands.get(commandName);

if (!command) {
console.error(`Command ${commandName} not found`);
return;
}

// Checking for the presence of the execute function
if (typeof command.execute !== 'function') {
console.error(`Command ${commandName} does not have an execute function`);
return;
}

try {
// Pass the client, message and arguments
command.execute(client, message, args);
} catch (error) {
console.error(`Error executing command: ${error}`);
message.reply('There was an error trying to execute that command!');
}
});

// Когда бот готов
client.on("ready", () => {
client.user.setActivity('Set Activity', { type: 'WATCHING' });
});

client.login(config.token)
client.login(config.token);

exports.client = client;
25 changes: 0 additions & 25 deletions src/commands/8-ball.js

This file was deleted.

84 changes: 46 additions & 38 deletions src/commands/ban.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,49 @@
const discord = require ("discord.js");
const prefix = require('../config/config.json')
const { EmbedBuilder } = require("discord.js");
const prefix = require('../config/config.json');

module.exports.run = (client, message, args) =>{
const {member, mentions } = message
module.exports.details = {
name: 'Ban',
author: 'LachlanDev#8014',
icon: 'https://cdn.discordapp.com/avatars/365350852967399454/ce6e6e91fa887aa86e23ef356c9878fe',
description: 'Bans a user from the server.',
usage: `${prefix.prefix}ban {@user}`
};

const tag = `<@${member.id}>`
if(message.guild.me.hasPermission('BAN_MEMBERS')){
if(
member.hasPermission('ADMINISTRATOR') ||
member.hasPermission('BAN_MEMBERS')){
const target = mentions.users.first()
if(target){
const targetMember = message.guild.members.cache.get(target.id)
targetMember.ban()
const kick = new discord.MessageEmbed()
.setColor('#e6350e')
.setTitle(`User Banned`)
.addField("User",`${target} was banned from the server!`)
.addField("Moderator",`${member}`)
.setThumbnail(target.avatarURL())
.setFooter("Made by LachlanDev#8014", "https://cdn.discordapp.com/avatars/365350852967399454/ce6e6e91fa887aa86e23ef356c9878fe")
message.channel.send({embed: kick })
}else{
message.channel.send(`${tag} please specify a user!`)
}
}else{
message.channel.send(`${tag} you dont have permission.`)
}
}else{
message.channel.send(`${tag} Sorry I dont have permission to Ban Members!`)
}
}
module.exports.execute = async (client, message, args) => {
const { member, mentions } = message;
const tag = `<@${member.id}>`;

module.exports.details = {
name:'Ban',
author:'LachlanDev#8014',
icon:'https://cdn.discordapp.com/avatars/365350852967399454/ce6e6e91fa887aa86e23ef356c9878fe',
description:'Bans a user from the server.',
usage:`${prefix.prefix}ban {@user}`
}
// Проверяем, есть ли у бота разрешения
if (!message.guild.me || !message.guild.me.permissions.has('BAN_MEMBERS')) {
return message.channel.send(`${tag} Sorry, I don't have permission to ban users!`);
}

// Проверяем, есть ли у пользователя разрешения
if (!member.permissions.has('ADMINISTRATOR') && !member.permissions.has('BAN_MEMBERS')) {
return message.channel.send(`${tag} You don't have permission.`);
}

const target = mentions.users.first();
if (target) {
const targetMember = message.guild.members.cache.get(target.id);
try {
await targetMember.ban();
const banEmbed = new EmbedBuilder()
.setColor('#e6350e')
.setTitle('User banned')
.addFields(
{ name: 'User', value: `${target} has been banned from the server!` },
{ name: 'Moderator', value: `${member}` }
)
.setThumbnail(target.displayAvatarURL())
.setFooter({ text: 'Made by LachlanDev#8014', iconURL: 'https://cdn.discordapp.com/avatars/365350852967399454/ce6e6e91fa887aa86e23ef356c9878fe' });

await message.channel.send({ embeds: [banEmbed] });
} catch (error) {
console.error(error);
message.channel.send(`${tag} An error occurred while trying to ban this user.`);
}
} else {
message.channel.send(`${tag} Please specify the user!`);
}
};
25 changes: 0 additions & 25 deletions src/commands/cat.js

This file was deleted.

Loading

0 comments on commit c303813

Please sign in to comment.