Creating a Basic Bot
Learn how to create a simple Discord bot with meowcord.
Setting Up Your Bot
After installing meowcord, the first step is to create a new instance of the Meow client with your preferred settings. Here's a basic setup:
const { Meow, Intents } = require("meowcord");
const bot = new Meow({
intents: [Intents.Guilds, Intents.GuildMessages, Intents.MessageContent],
prefix: "!",
meowSettings: {
returnBotInfosInConsole: true
},
});
bot.start("YOUR_BOT_TOKEN");
This code initializes your bot with the necessary intents and a prefix for commands. The returnBotInfosInConsole
setting will display useful information about your bot when it starts.
Adding Basic Commands
Basic commands are the simplest way to add functionality to your bot. Here's how to add a ping command:
bot.basicCommand({
cmdName: "ping",
cmdCode: async (message) => {
const ping = Date.now() - message.createdTimestamp;
message.reply(`🏓 Pong! My ping is currently ${ping}ms`);
}
});
When a user types !ping
in a channel your bot has access to, it will respond with the ping measurement.
Adding Multiple Commands
You can add as many commands as you need:
// A hello command
bot.basicCommand({
cmdName: "hello",
cmdCode: async (message) => {
message.reply("Hello there! How can I help you today?");
}
});
// An info command
bot.basicCommand({
cmdName: "info",
cmdCode: async (message) => {
message.reply("I am a bot created with meowcord!");
}
});
Command Parameters
You can also create commands that accept parameters:
bot.basicCommand({
cmdName: "say",
cmdCode: async (message) => {
const args = message.content.slice(bot.prefix.length + 3).trim();
if (!args) return message.reply("You need to provide something for me to say!");
message.reply(args);
}
});
This command takes everything after !say
and sends it back as a message.
Complete Basic Bot Example
Here's a complete example of a basic bot with multiple commands:
const { Meow, Intents } = require("meowcord");
const bot = new Meow({
intents: [Intents.Guilds, Intents.GuildMessages, Intents.MessageContent],
prefix: "!",
meowSettings: {
returnBotInfosInConsole: true
},
});
// Start the bot
bot.start("YOUR_BOT_TOKEN");
// Ping command
bot.basicCommand({
cmdName: "ping",
cmdCode: async (message) => {
const ping = Date.now() - message.createdTimestamp;
message.reply(`🏓 Pong! My ping is currently ${ping}ms`);
}
});
// Hello command
bot.basicCommand({
cmdName: "hello",
cmdCode: async (message) => {
message.reply("Hello there! How can I help you today?");
}
});
// Info command
bot.basicCommand({
cmdName: "info",
cmdCode: async (message) => {
message.reply("I am a bot created with meowcord!");
}
});
// Say command
bot.basicCommand({
cmdName: "say",
cmdCode: async (message) => {
const args = message.content.slice(bot.prefix.length + 3).trim();
if (!args) return message.reply("You need to provide something for me to say!");
message.reply(args);
}
});