This repository has been archived by the owner on Jun 18, 2022. It is now read-only.
generated from NamVr/DiscordBot-Template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7c9e65b
commit faf581b
Showing
6 changed files
with
206 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module.exports = { | ||
name: "ban", | ||
description: "Ban the user", | ||
category: "moderation", | ||
usage: "ban <Ping user>", | ||
guildOnly: true, | ||
/** | ||
* @description Executes when the command is called by command handler. | ||
* @author Vachan MN | ||
* @param {Object} message The Message Object of the command. | ||
* @param {String[]} args The Message Content of the received message seperated by spaces (' ') in an array, this excludes prefix and command/alias itself. | ||
*/ | ||
|
||
execute(message, args) { | ||
// Check if the user has the permission to ban. | ||
if (!message.member.hasPermission("BAN_MEMBERS")) { | ||
return message.channel.send( | ||
`${message.author} You don't have permission to ban members.` | ||
); | ||
} | ||
// Ban the user mentioned | ||
if (message.mentions.users.size) { | ||
const user = message.mentions.users.first(); | ||
message.guild.member(user).ban(); | ||
message.channel.send(`${message.author} Banned ${user}`); | ||
} else { | ||
message.channel.send(`${message.author} You need to mention a user to ban.`); | ||
} | ||
|
||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/** | ||
* @author: Vachan MN | ||
* @file: This file contains the database object class | ||
* @version: 1.0 | ||
* | ||
*/ | ||
|
||
const fs = require("fs"); | ||
|
||
class Database { | ||
/** | ||
* @description Constructor for the Database class | ||
* @param {string} path Path to the database file | ||
* @param {Object} client bot client | ||
*/ | ||
constructor(path, client){ | ||
this.path = path; | ||
this.client = client; | ||
let db = undefined; | ||
try{ | ||
db = fs.readdirSync(path); | ||
console.log("Loaded database"); | ||
}catch(e){ | ||
console.log("Database not found, Creating new Database"); | ||
fs.mkdirSync(path); | ||
db = fs.readdirSync(path); | ||
console.log("Loaded Database"); | ||
} | ||
const Guilds = client.guilds.cache.map(g => g); | ||
for (const server of Guilds) { | ||
try{ | ||
fs.readdirSync(path + "/" + server.id); | ||
console.log("Loaded server database for " + server.name); | ||
} catch(e){ | ||
console.log("Database not found, Creating new Database for " + server.name); | ||
fs.mkdirSync(path + "/" + server.id); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @description Get a server db object | ||
* @param {string} serverId Server ID | ||
* @returns {fs.Dir} Server Database Object | ||
*/ | ||
|
||
getServerDb(serverId){ | ||
const path = this.path + "/" + serverId; | ||
const db = fs.readdirSync(path); | ||
return db; | ||
} | ||
|
||
/** | ||
* @description Add a new collection to the database | ||
* @param {string} serverId Server ID | ||
* @param {string} collectionName Collection Name | ||
* @returns {Object} Collection json object | ||
*/ | ||
addCollection(serverId, collectionName){ | ||
const path = this.path + "/" + serverId + "/" + collectionName + ".json"; | ||
let collection = undefined; | ||
try{ | ||
const collection = fs.readdirSync(path); | ||
console.log("Collection already exists"); | ||
} catch (e){ | ||
fs.writeFileSync(path, JSON.stringify({})); | ||
console.log("Collection created"); | ||
collection = fs.readdirSync(path); | ||
} | ||
return db; | ||
} | ||
|
||
/** | ||
* @description Get a collection from the database | ||
* @param {string} serverId Server ID | ||
* @param {string} collectionName Collection Name | ||
* @returns {Object} Collection json object | ||
*/ | ||
getCollection(serverId, collectionName){ | ||
const path = this.path + "/" + serverId + "/" + collectionName + ".json"; | ||
let collection = undefined; | ||
try{ | ||
collection = fs.readdirSync(path); | ||
console.log("Collection found"); | ||
} catch (e){ | ||
console.log("Collection not found"); | ||
} | ||
return collection; | ||
} | ||
|
||
/** | ||
* @description update the collection | ||
* @param {string} serverId Server ID | ||
* @param {string} collectionName Collection Name | ||
* @param {Object} collection Collection Object | ||
*/ | ||
updateCollection(serverId, collectionName, collection){ | ||
const path = this.path + "/" + serverId + "/" + collectionName + ".json"; | ||
try{ | ||
fs.writeFileSync(path, JSON.stringify(collection)); | ||
console.log("Collection updated"); | ||
} catch (e){ | ||
console.log("Collection not found"); | ||
} | ||
} | ||
} | ||
|
||
module.exports = Database; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* @file Add a song to the queue | ||
* @author Vachan MN | ||
* @since 3.0.0 | ||
*/ | ||
|
||
// Deconstructed the constants we need in this file. | ||
|
||
const { MessageEmbed } = require("discord.js"); | ||
const { SlashCommandBuilder } = require("@discordjs/builders"); | ||
|
||
module.exports = { | ||
// The data needed to register slash commands to Discord. | ||
data: new SlashCommandBuilder() | ||
.setName("add") | ||
.setDescription( | ||
"Add a song" | ||
) | ||
.addStringOption((option) => | ||
option | ||
.setName("songsearch") | ||
.setDescription("Enter the song's URL or name") | ||
.setRequired(true) | ||
), | ||
|
||
/** | ||
* @description Executes when the interaction is called by interaction handler. | ||
* @author Vachan MN | ||
* @param {*} interaction The interaction object of the command. | ||
*/ | ||
|
||
async execute(interaction) { | ||
/** | ||
* @type {Object[]} | ||
* @description Array of all slash commands objects earlier registered. | ||
*/ | ||
|
||
const { guild, author, channel, args } = interaction; | ||
const client = interaction.client; | ||
const searchString = args.join(" "); | ||
if (!author.voice.channel) return interaction.reply('YOU ARENT IN A VC!'); | ||
if (!searchString) return interaction.reply("Please provide a search query!"); | ||
try { | ||
await interaction.channel.sendTyping(); | ||
await client.distube.play(interaction.message, args.join(' '), {unshift: true}); | ||
} catch (e) { | ||
return interaction.reply(e); | ||
} | ||
|
||
}, | ||
}; |