Better command parsing
This commit is contained in:
parent
f429656c0b
commit
16b56302ba
@ -1,4 +1,5 @@
|
|||||||
const client = require("../index")
|
const {client, commands} = require("../index")
|
||||||
|
const { EmbedBuilder, Message, Colors } = require("discord.js")
|
||||||
|
|
||||||
module.exports = [
|
module.exports = [
|
||||||
{
|
{
|
||||||
@ -6,6 +7,30 @@ module.exports = [
|
|||||||
run: (ctx, args) => {
|
run: (ctx, args) => {
|
||||||
console.log(ctx, args)
|
console.log(ctx, args)
|
||||||
ctx.reply(`Pong! ${args}`)
|
ctx.reply(`Pong! ${args}`)
|
||||||
|
},
|
||||||
|
hide: false,
|
||||||
|
arguments: ["any"],
|
||||||
|
description: "Check how fast bot will reply!"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "help",
|
||||||
|
run: (ctx, args) => {
|
||||||
|
const embed = new EmbedBuilder()
|
||||||
|
.setAuthor({name: ctx.author.username, iconURL: ctx.author.avatarURL(), url: "https://git.squog.ru/entar/SquogAdmin"})
|
||||||
|
.setColor(Colors.White)
|
||||||
|
|
||||||
|
commands.forEach(commandList => {
|
||||||
|
commandList.forEach(command => {
|
||||||
|
if (command.hide) {
|
||||||
|
return // Go to next command if this one should show up
|
||||||
}
|
}
|
||||||
|
const field = {name: command.name, value: `Description: ${command.description || "None"}\nArguments: ${command.arguments || "None"}`}
|
||||||
|
console.log(field)
|
||||||
|
embed.addFields(field)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
ctx.reply({embeds: [embed]})
|
||||||
|
},
|
||||||
|
hide: true,
|
||||||
}
|
}
|
||||||
]
|
]
|
17
commands/extra.js
Normal file
17
commands/extra.js
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
const {client} = require("../index")
|
||||||
|
const { GuildMember, GuildChannel } = require("discord.js")
|
||||||
|
|
||||||
|
module.exports = [
|
||||||
|
{
|
||||||
|
name: "helptest",
|
||||||
|
description: "Kill every1",
|
||||||
|
arguments: [GuildMember.name, GuildChannel.name],
|
||||||
|
run: (ctx, args) => {
|
||||||
|
if (!args[0].user) {
|
||||||
|
ctx.reply("Member invalid.")
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.reply(`Member: ${args[0]}\nChannel: ${args[1]}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
31
index.js
31
index.js
@ -19,7 +19,8 @@ const client = new Client({
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Exporting the client for event and command files to use it
|
// Exporting the client for event and command files to use it
|
||||||
module.exports = {client: client, dir: __dirname}
|
module.exports.client = client
|
||||||
|
module.exports.dir = __dirname
|
||||||
|
|
||||||
// Requiring all the event files.
|
// Requiring all the event files.
|
||||||
fs.readdir(`${__dirname}/events/`, (err, files) => {
|
fs.readdir(`${__dirname}/events/`, (err, files) => {
|
||||||
@ -61,7 +62,7 @@ function getCommand(commandName) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parsing commands on message create
|
// Parsing commands on message create
|
||||||
client.on("messageCreate", async (message) => {
|
client.on("messageCreate", (message) => {
|
||||||
var content = message.content
|
var content = message.content
|
||||||
|
|
||||||
// Continue only if starts with the prefix
|
// Continue only if starts with the prefix
|
||||||
@ -81,6 +82,30 @@ client.on("messageCreate", async (message) => {
|
|||||||
// Removing command from the args
|
// Removing command from the args
|
||||||
const args = parsed.filter(value => {return value != command})
|
const args = parsed.filter(value => {return value != command})
|
||||||
|
|
||||||
|
// Parsing
|
||||||
|
args.forEach((arg, index) => {
|
||||||
|
console.log(index)
|
||||||
|
if (arg.startsWith("<@")) {
|
||||||
|
// User, lets get the id
|
||||||
|
const id = arg.slice(2, arg.length - 1)
|
||||||
|
|
||||||
|
const member = message.guild.members.cache.find(member => member.user.id == id)
|
||||||
|
|
||||||
|
if (member) {
|
||||||
|
args[index] = member
|
||||||
|
}
|
||||||
|
} else if (arg.startsWith("<#")) {
|
||||||
|
// Channel, lets get the id
|
||||||
|
const id = arg.slice(2, arg.length - 1)
|
||||||
|
|
||||||
|
const channel = message.guild.channels.cache.find(channel => channel.id == id)
|
||||||
|
|
||||||
|
if (channel) {
|
||||||
|
args[index] = channel
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// Actual command
|
// Actual command
|
||||||
const realCommand = getCommand(command)
|
const realCommand = getCommand(command)
|
||||||
|
|
||||||
@ -93,5 +118,7 @@ client.on("messageCreate", async (message) => {
|
|||||||
realCommand.run(message, args)
|
realCommand.run(message, args)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
module.exports.commands = commands
|
||||||
|
|
||||||
// Time to login
|
// Time to login
|
||||||
client.login(token)
|
client.login(token)
|
Loading…
x
Reference in New Issue
Block a user