Discord.js v13 bot cannot send message

Viewed 27

Here is my code I tried to run it and when i run the command nothing shows up can someone pls help me with this

const Discord = require("discord.js");
const bot = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"] });

const token =
  "MTAxNzgyMjQ1MjU1MTc5NDgxOA.GjO8F-.VWCMsDKV5_YdP1w6gnEME6Jucd7BN9OADesM4s";
const prefix = "lb!";
bot.on("ready", () => {
  console.log("Your bot is now online");
});

bot.on("messagecreate", (message) => {
  if (message.author.bot) return;

  const args = message.content.slice(prefix.length).trim().split(/ +/g);
  const command = args.shift().toLocaleLowerCase();

  if (command === "hello") {
    message.reply("Hi ${message.author}");
  }
});

bot.login(token);

3 Answers

Message content is now a privileged intent. You may have to enable it for your bot in the Discord Developer Portal. You could (or should) also use interaction commands instead, so that you don't need that intent, as its purpose is to provide user privacy.

Hello Syed Faizan Ali Kazmi, Done Fix Your Code

// © Ahmed1Dev
const Discord = require("discord.js");
const bot = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"] });

const token =
  "MTAxNzgyMjQ1MjU1MTc5NDgxOA.GjO8F-.VWCMsDKV5_YdP1w6gnEME6Jucd7BN9OADesM4s";
const prefix = "lb!";
bot.on("ready", () => {
  console.log("Your bot is now online");
});

bot.on("messagecreate", (message) => {
  if (message.author.bot) return;

  const args = message.content.slice(prefix.length).trim().split(/ +/g);
  const command = args.shift().toLocaleLowerCase();

  if (command === prefix + "hello") {
    message.reply("Hi ${message.author}");
  }
});

bot.login(token);
// © Ahmed1Dev

With Regards, Ahmed1Dev

I rewrite the code. Hope this will work

const Discord = require("discord.js");
const bot = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"] });

const token = "never post your bot token online";
const prefix = "lb!";
bot.on("ready", () => {
  console.log("Your bot is now online");
});

bot.on("messageCreate", (message) => {
  if (message.author.bot) return;

  const args = message.content.slice(prefix.length).trim().split(/ +/g);
  const command = args.shift().toLowerCase();

  if (command === "hello") {
    message.reply(`Hi ${message.author}`);
  }
});

bot.login(token);

Also, if you didn't tick Message Content Intent, then go tick it in Discord Developer Portal

Related