Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///cc-create command:
- const db = require('../../models/CC')
- const Discord = require('discord.js')
- module.exports = {
- name: "cc-create",
- description: "Creates a custom command!",
- category: "config",
- usage: "cc-create <name> <response>",
- example: "cc-create pog poggies",
- aliases: [`ccc`, `cccreate`, `customcommandcreate`, `custom-command-create`],
- botPermission: [],
- authorPermission: [`MANAGE_GUILD`],
- guildOnly: true,
- cooldown: "3s",
- ownerOnly: false,
- run: async (bot, message, args, noPerms) => {
- const name = args[0]
- const response = args.slice(1).join(" ")
- if (!name || !response) return message.channel.send(
- new Discord.MessageEmbed()
- .setAuthor(message.author.tag, message.author.displayAvatarURL({ dynamic: true }))
- .setColor(bot.color)
- .setDescription(`Please provide a response and a name.`)
- .addField(`Usage`, `\`ccc <name> <response>\``)
- .addField(`Options`,
- `\`{author}\` - pings the message author\n\`{server.name}\` - sends the servers name.\n\`{channel}\` - pings the message channel.\n\`{author.id}\` - sends the authors id.\n\`{author.username}\` - sends the author usernames\n\`{author.name}\` - sends the authors name and tag.\n\`{author.discriminator}\` - sends the author discriminator.\n\`{author.avatar}\` - sends the authors avatar\n\`{author.createdAt}\` - sends the authors creation date\n\`{author.joinedAt}\` - sends when the user joined the server.\n\`{server.id}\` - sends the servers id.\n\`{server.icon}\` - sends the servers icon\n\`{server.members}\` - sends the servers members\n\`{server.ownerID}\` - sends the servers owner id\n\`{channel.id}\` - sends the message channels id\n\`{channel.name}\` - sends the channels name`
- )
- )
- await db.findOne({ Guild: message.guild.id, Command: name }, async (err, data) => {
- if (err) throw err
- if (data) {
- return message.channel.send(`This custom command already exists.`)
- } else if (!data) {
- if (response.includes(`{message}`)) {
- new db({
- Guild: message.guild.id,
- Command: name,
- Response: response,
- Req: true
- }).save()
- return message.channel.send(
- new Discord.MessageEmbed()
- .setAuthor(`Custom Command Created`, message.author.displayAvatarURL({ dynamic: true }))
- .setColor(bot.color)
- .addField(`Command`, name, true)
- .addField(`Required Argument`, `True`, true)
- .addField(`Response`, `\`\`\`\n${response}\n\`\`\``, true)
- )
- } else {
- new db({
- Guild: message.guild.id,
- Command: name,
- Response: response
- }).save()
- return message.channel.send(
- new Discord.MessageEmbed()
- .setAuthor(`Custom Command Created`, message.author.displayAvatarURL({ dynamic: true }))
- .setColor(bot.color)
- .addField(`Command`, name)
- .addField(`Response`, `\`\`\`\n${response}\n\`\`\``)
- )
- }
- }
- })
- }
- }
- /////cc-delete command:
- const db = require('../../models/CC')
- module.exports = {
- name: "cc-delete",
- description: "Deleted a custom command!",
- category: "config",
- usage: "cc-delete <name>",
- example: "cc-create pog",
- aliases: [`ccd`, `ccdelete`, `customcommanddelete`, `custom-command-delete`],
- botPermission: [],
- authorPermission: [`MANAGE_GUILD`],
- guildOnly: true,
- cooldown: "3s",
- ownerOnly: false,
- run: async (bot, message, args, noPerms) => {
- const name = args[0]
- if (!name) return noPerms(bot, message, `Please provide a name.`, `cc-delete <name>`)
- await db.findOne({ Guild: message.guild.id, Command: name }, async (err, data) => {
- if (err) throw err
- if (!data) return message.channel.send(`\`${name}\` does not exists.`)
- else if (data) {
- await db.findOneAndDelete({ Guild: message.guild.id, Command: name })
- return message.channel.send(`Deleted \`${name}\`.`)
- }
- })
- }
- }
- ///cc-list command:
- const db = require('../../models/CC')
- const Discord = require('discord.js')
- module.exports = {
- name: "cc-list",
- description: "Lists all the custom commands!",
- category: "config",
- usage: "",
- example: "",
- aliases: [`ccl`, `cclist`, `customcommandlist`, `custom-command-list`],
- botPermission: [],
- authorPermission: [],
- guildOnly: true,
- cooldown: "3s",
- ownerOnly: false,
- run: async (bot, message, args) => {
- const data = await db.find({ Guild: message.guild.id })
- if (data === false) return message.channel.send(`There are no custom commands in the server.`)
- message.channel.send(
- new Discord.MessageEmbed()
- .setTitle(`\`${message.guild.name}\`'s Custom Commands`)
- .setThumbnail(message.guild.iconURL({ dynamic: true }))
- .setColor(bot.color)
- .setDescription(data.map((cmd, i) =>
- `**${i + 1}.** ${cmd.Command}`
- ).join("\n"))
- )
- }
- }
- ///the mongoose model:
- const { Schema, model } = require('mongoose')
- const data = Schema({
- Guild: String,
- Command: String,
- Response: String,
- Req: { type: String, require: false }
- })
- module.exports = model('custom-commands', data)
- /////put this in your message event:
- const ccDb = require('../models/CC')
- const ccData = await ccDb.findOne({ Guild: message.guild.id, Command: cmd })
- if (ccData) {
- if (ccData.Response.includes(`{embed}`) && ccData.Response.includes(`{message}`)) {
- if (!args[0]) return message.channel.send(`The \`${ccData.Command}\` required you to provide an argument. Ex: \`${ccData.Command} pog\`.`)
- let newResponse = ccData.Response
- .replace(`{author}`, message.author)
- .replace(`{server.name}`, message.guild.name)
- .replace(`{channel}`, message.channel)
- .replace(`{author.id}`, message.author.id)
- .replace(`{author.username}`, message.author.username)
- .replace(`{author.name}`, message.author.tag)
- .replace(`{author.discriminator}`, message.author.discriminator)
- .replace(`{author.avatar}`, message.author.displayAvatarURL({ dynamic: true }))
- .replace(`{author.createdAt}`, message.author.createdAt.toString())
- .replace(`{author.joinedAt}`, message.member.joinedAt.toString())
- .replace(`{server.id}`, message.guild.id)
- .replace(`{server.icon}`, message.guild.iconURL({ dynamic: true }))
- .replace(`{server.members}`, message.guild.memberCount)
- .replace(`{server.ownerID}`, message.guild.ownerID)
- .replace(`{channel.id}`, message.channel.id)
- .replace(`{channel.name}`, message.channel.name)
- .replace(`{message}`, args[0])
- .replace(`{embed}`, '')
- return message.channel.send(new MessageEmbed().setDescription(newResponse).setColor(bot.color))
- } else if (ccData.Response.includes(`{embed}`)) {
- let newResponse = ccData.Response
- .replace(`{author}`, message.author)
- .replace(`{server.name}`, message.guild.name)
- .replace(`{channel}`, message.channel)
- .replace(`{author.id}`, message.author.id)
- .replace(`{author.username}`, message.author.username)
- .replace(`{author.name}`, message.author.tag)
- .replace(`{author.discriminator}`, message.author.discriminator)
- .replace(`{author.avatar}`, message.author.displayAvatarURL({ dynamic: true }))
- .replace(`{author.createdAt}`, message.author.createdAt.toString())
- .replace(`{author.joinedAt}`, message.member.joinedAt.toString())
- .replace(`{server.id}`, message.guild.id)
- .replace(`{server.icon}`, message.guild.iconURL({ dynamic: true }))
- .replace(`{server.members}`, message.guild.memberCount)
- .replace(`{server.ownerID}`, message.guild.ownerID)
- .replace(`{channel.id}`, message.channel.id)
- .replace(`{channel.name}`, message.channel.name)
- .replace(`{embed}`, '')
- return message.channel.send(new MessageEmbed().setDescription(newResponse).setColor(bot.color))
- } else if (ccData.Response.includes(`{message}`)) {
- if (!args[0]) return message.channel.send(`The \`${ccData.Command}\` required you to provide an argument. Ex: \`${ccData.Command} pog\`.`)
- let newResponse = ccData.Response
- .replace(`{author}`, message.author)
- .replace(`{server.name}`, message.guild.name)
- .replace(`{channel}`, message.channel)
- .replace(`{author.id}`, message.author.id)
- .replace(`{author.username}`, message.author.username)
- .replace(`{author.name}`, message.author.tag)
- .replace(`{author.discriminator}`, message.author.discriminator)
- .replace(`{author.avatar}`, message.author.displayAvatarURL({ dynamic: true }))
- .replace(`{author.createdAt}`, message.author.createdAt.toString())
- .replace(`{author.joinedAt}`, message.member.joinedAt.toString())
- .replace(`{server.id}`, message.guild.id)
- .replace(`{server.icon}`, message.guild.iconURL({ dynamic: true }))
- .replace(`{server.members}`, message.guild.memberCount)
- .replace(`{server.ownerID}`, message.guild.ownerID)
- .replace(`{channel.id}`, message.channel.id)
- .replace(`{channel.name}`, message.channel.name)
- .replace(`{message}`, args[0])
- return message.channel.send(newResponse)
- } else {
- let newResponse = ccData.Response
- .replace(`{author}`, message.author)
- .replace(`{server.name}`, message.guild.name)
- .replace(`{channel}`, message.channel)
- .replace(`{author.id}`, message.author.id)
- .replace(`{author.username}`, message.author.username)
- .replace(`{author.name}`, message.author.tag)
- .replace(`{author.discriminator}`, message.author.discriminator)
- .replace(`{author.avatar}`, message.author.displayAvatarURL({ dynamic: true }))
- .replace(`{author.createdAt}`, message.author.createdAt.toString())
- .replace(`{author.joinedAt}`, message.member.joinedAt.toString())
- .replace(`{server.id}`, message.guild.id)
- .replace(`{server.icon}`, message.guild.iconURL({ dynamic: true }) || "This server doesn't have a icon.")
- .replace(`{server.members}`, message.guild.memberCount)
- .replace(`{server.ownerID}`, message.guild.ownerID)
- .replace(`{channel.id}`, message.channel.id)
- .replace(`{channel.name}`, message.channel.name)
- return message.channel.send(newResponse)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment