-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[New] Created setup command to set custom prefix for servers in the d…
…atabase
- Loading branch information
Showing
1 changed file
with
127 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
const { SlashCommandBuilder } = require("@discordjs/builders"); | ||
const { embedMessage } = require("../../modules/embedSimple"); | ||
const { prefix } = require("../../config.json"); | ||
|
||
module.exports = { | ||
name: "prefix", | ||
aliases: ["setup"], | ||
description: "set custom prefix for your server", | ||
args: true, | ||
usage: `${prefix}prefix set <new prefix>`, | ||
async run(message, args, client, defaultPrefix) { | ||
if (!message.member.permissions.has("MANAGE_GUILD")) | ||
return await message.channel.send({ | ||
embeds: [ | ||
embedMessage( | ||
"#9dcc37", | ||
`❌ You do not have permission to change the prefix!` | ||
), | ||
], | ||
}); | ||
|
||
if (!args[0]) | ||
return await message.channel.send({ | ||
embeds: [ | ||
embedMessage("#9dcc37", `❌ You did not provide your new prefix!`), | ||
], | ||
}); | ||
|
||
if (args[1]) | ||
return await message.channel.send({ | ||
embeds: [embedMessage("#9dcc37", `❌ Prefix can't have 2 arguments`)], | ||
}); | ||
|
||
if (args.join(" ") === prefix) { | ||
await client.db.delete(`guild_prefix_${message.guildId}`); | ||
return await message.channel.send({ | ||
embeds: [ | ||
embedMessage( | ||
"#9dcc37", | ||
`✅ Bot Prefix Resetted to ` + "`" + `${prefix}` + "`" | ||
), | ||
], | ||
}); | ||
} | ||
|
||
try { | ||
await client.db.set(`guild_prefix_${message.guildId}`, args[0]); | ||
await message.channel.send({ | ||
embeds: [ | ||
embedMessage( | ||
"#9dcc37", | ||
`✅ Bot Prefix set to ` + "`" + `${args[0]}` + "`" | ||
), | ||
], | ||
}); | ||
} catch (err) { | ||
client.logger(err.message, "error"); | ||
await message.channel.send({ | ||
embeds: [ | ||
embedMessage( | ||
"#9dcc37", | ||
`❌ There has been an error, Could not set the new Prefix` | ||
), | ||
], | ||
}); | ||
} | ||
}, | ||
|
||
data: new SlashCommandBuilder() | ||
.setName("prefix") | ||
.setDescription("set custom prefix for your server") | ||
.addStringOption((option) => | ||
option | ||
.setName("newprefix") | ||
.setDescription("Your new Prefix") | ||
.setRequired(true) | ||
), | ||
async execute(interaction, client) { | ||
const newPrefix = interaction.options.getString("newprefix"); | ||
await interaction.deferReply(); | ||
|
||
if (!interaction.member.permissions.has("MANAGE_GUILD")) { | ||
return await interaction.followUp({ | ||
embeds: [ | ||
embedMessage( | ||
"#9dcc37", | ||
`You do not have permission to change the prefix` | ||
), | ||
], | ||
}); | ||
} | ||
|
||
if (newPrefix === prefix) { | ||
await client.db.delete(`guild_prefix_${interaction.guildId}`); | ||
return await interaction.followUp({ | ||
embeds: [ | ||
embedMessage( | ||
"#9dcc37", | ||
`✅ Bot Prefix Resetted to ` + "`" + `${prefix}` + "`" | ||
), | ||
], | ||
}); | ||
} | ||
|
||
try { | ||
await client.db.set(`guild_prefix_${interaction.guildId}`, newPrefix); | ||
await interaction.followUp({ | ||
embeds: [ | ||
embedMessage( | ||
"#9dcc37", | ||
`✅ Bot Prefix set to ` + "`" + `${newPrefix}` + "`" | ||
), | ||
], | ||
}); | ||
} catch (err) { | ||
client.logger(err.message, "error"); | ||
await interaction.followUp({ | ||
embeds: [ | ||
embedMessage( | ||
"#9dcc37", | ||
`❌ There has been an error, Could not set the new Prefix` | ||
), | ||
], | ||
}); | ||
} | ||
}, | ||
}; |