0
votes

does anyone have a complete latest basic discord code with say command? Or anyone willing to teach me and guide me to make the bot. I'm dying to make one for my bot :'(

1
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. - Community

1 Answers

1
votes

Stackoverflow isn't a code writing service and we expect you to have minimal knowledge of javascript / discord.js while working with it,

Although I'd help you go through your pain! Welcome to stackoverflow 😄.

For starters let's require discord.js and initialise a Client

const { Client, Intents } = require("discord.js");
const client = new Client({ intents: 4609 }); // This is intents bitfield value for DIRECT_MESSAGES, GUILD_MESSAGES and GUILD intents 

Now let's set up our event listener for the messageCreate so we can reply when an user messages, simultaneously we would define the prefix, command and user arguments

const { Client, Intents } = require("discord.js");
const client = new Client({ intents: 4609 });
const prefix = "!"; 
client.on("messageCreate" ,  (message) => {
const args = message.content.slice(prefix.length).trim().split(/+ /); // defining what are arguments ( eg. !say hello, hello is our argument ) 
const command = args.shift().toLowerCase();  // defining what a command is ( our first word to lowercase eg. !say hello then !say is our comamnd )
if(message.author.bot) return  // this is called botception, ignoring bot messages basically
if(command == "say") { // if the command is !say then repeat everything after the command 
message.reply(args.join(" ")); // eg. if user says !say hello welcome to stackoverflow, bot would reply with hello welcome to stackoverflow
message.delete(); // deleting the message from the user 
}
});
client.login("your_token_here");

Here are some useful resources for beginners to start up creating bots!

• Discord Developer Portal
• Discord.js Beginners' Guide