Guide To Create Custom Guild Prefix Command For Discord Bot Very Easily

Every famous and good bot have its custom guild prefix and if you want your bot to have this cool feature then follow this guide. I will be using quick.db to store server guild prefix.

First go to main file which is server.js in my case and define quick.db package as we are going to use it to store the guild prefix. Before doing anything go to config file change prefix to default prefix and do same in server.js.

  "token": "TOKEN",
  "default_prefix": "!"
const { token, default_prefix } = require("./config.json")
const db = require("quick.db")

I will be using my command handle if you do not know how to create it then check out this post – HERE

Now head to message event

client.on("message", async message => {
if(!message.guild) return;
  let prefix = db.get(`prefix_${}`)
  if(prefix === null) prefix = default_prefix;
  if(!message.content.startsWith(prefix)) return;

After this we are done with setup and it’s time to create command to set prefix.

Create command with name prefix, We will make sure while using prefix command author should have admin permissions to change the bot guild prefix.

   if(!message.member.hasPermission("ADMINISTRATOR")) {
      return"You are not allowed or do not have permission to change prefix")

We will see if the author send anything or not to set prefix

  if(!args[0]) {
      return"Please give the prefix that you want to set")

Now we will also make sure author do not give argument more than 1

 if(args[1]) {
      return"You can not set prefix a double argument")

We have to make sure that author does not give prefix, so we will be adding if statement with args[0]

 if(args[0].length > 3) {
      return"You can not send prefix more than 3 characters")

What if author set prefix to default prefix, and we do not want our bot storage to fill out, so we will be deleting prefix if author give default prefix while setting prefix.

 if(args.join("") === default_prefix) {
     return await"Reseted Prefix ✅")

Now time to send success message.

    db.set(`prefix_${}`, args[0])
  await`Seted Bot Prefix to ${args[0]}`)

R>Result Code

Here is the result code – HERE

Related Posts

Written by Senpai

"This may be a virtual world,but I feel more alive here then in the real world"

Leave a Reply

One Comment