How to add custom commands? #375
-
How to add custom commands to my own Atlanta instance? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hello 👋Here is a step-by-step tutorial to learn how to create custom commands in the bot. In this tutorial, we will try to create a "say" command (for example *say hello will make the bot send hello). Step 1: create the fileThe first thing to do is to create a Then, open it. Step 2: add base contentEach command file has a "base" content, it allows you to define command settings like whether the command can be run in DM, if there are any aliases, etc. Copy the following code into the const Command = require("../../base/Command.js");
class BaseCommand extends Command {
constructor (client) {
super(client, {
name: "",
dirname: __dirname,
enabled: true,
guildOnly: false,
aliases: [],
memberPermissions: [],
botPermissions: [ "SEND_MESSAGES", "EMBED_LINKS" ],
nsfw: false,
ownerOnly: false,
cooldown: 5000
});
}
async run (message, args) {
}
}
module.exports = BaseCommand; So there are a few things to change there.
dirname should not be changed. It is used to determine the category of the command. So here is our new file after editions: const Command = require("../../base/Command.js");
class Say extends Command {
constructor (client) {
super(client, {
name: "say",
dirname: __dirname,
enabled: true, // yes it should be anabled
guildOnly: false, // no it can be run in DMs too
aliases: [ "s" ], // s is another name of the command
memberPermissions: [ "ADMINISTRATOR" ], // the user must be administrator of their server to run the command
botPermissions: [ "SEND_MESSAGES" ], // the bot only needs to send messages
nsfw: false, // no our command is not NSFW
ownerOnly: false, // no, server admins can also run this command
cooldown: 0 // no cooldown, we don't want the admins to be ratelimited
});
}
async run (message, args) {
}
}
module.exports = Say; Step 3: add the main contentHere we go! We now have to code our command! The code should be written in the run method. You have access to the client using async run (message, args) {
// as this is not a tutorial to learn to code, I won't detail the things below
const sayContent = args.join(' ');
message.delete();
message.channel.send(sayContent);
} And our command is done! Here is our final file: const Command = require("../../base/Command.js");
class Say extends Command {
constructor (client) {
super(client, {
name: "say",
dirname: __dirname,
enabled: true, // yes it should be anabled
guildOnly: false, // no it can be run in DMs too
aliases: [ "s" ], // s is another name of the command
memberPermissions: [ "ADMINISTRATOR" ], // the user must be administrator of their server to run the command
botPermissions: [ "SEND_MESSAGES" ], // the bot only needs to send messages
nsfw: false, // no our command is not NSFW
ownerOnly: false, // no, server admins can also run this command
cooldown: 0 // no cooldown, we don't want the admins to be ratelimited
});
}
async run (message, args) {
const sayContent = args.join(' ');
message.delete();
message.channel.send(sayContent);
}
}
module.exports = Say; Congratulations 🎉You did it! Feel free to add a ⭐ to the repository and react with 👍 if you enjoyed this tutorial and want more! |
Beta Was this translation helpful? Give feedback.
-
Is there a similar way to add embedded messages too? |
Beta Was this translation helpful? Give feedback.
Hello 👋
Here is a step-by-step tutorial to learn how to create custom commands in the bot. In this tutorial, we will try to create a "say" command (for example *say hello will make the bot send hello).
Step 1: create the file
The first thing to do is to create a
.js
file in the category folder of your choice. For example, you can create acommands/General/say.js
file.Then, open it.
Step 2: add base content
Each command file has a "base" content, it allows you to define command settings like whether the command can be run in DM, if there are any aliases, etc. Copy the following code into the
say.js
file: