[SOLVED] discord.js 12.5.3 can’t send message, but status online – Stack Overflow

Issue

This Content is from Stack Overflow. Question asked by MEF STREAM

Index.js

const Discord = require("discord.js");
const client = new Discord.Client({ disableMentions: 'everyone' });
require('dotenv').config();
const Eco = require("quick.eco");
client.eco = new Eco.Manager();
client.db = Eco.db; 
client.config = require("./config");
client.commands = new Discord.Collection();
client.aliases = new Discord.Collection();
const fs = require("fs");

fs.readdir("./events/", (err, files) => {
    if (err) return console.error(err);
    files.forEach(f => {
        if (!f.endsWith(".js")) return;
        const event = require(`./events/${f}`);
        let eventName = f.split(".")[0];
        client.on(eventName, event.bind(null, client));
    });
});

fs.readdir("./commands/", (err, files) => {
    if (err) return console.error(err);
    files.forEach(f => {
        if (!f.endsWith(".js")) return;
        let command = require(`./commands/${f}`);
        client.commands.set(command.help.name, command);
        command.help.aliases.forEach(alias => {
            client.aliases.set(alias, command.help.name);
        });
    });
});


client.login(process.env.TOKEN);

Message.js

const { MessageEmbed } = require('discord.js');
const fs = require('fs');
let visitor = require('../database/visitor.json');
let level = require('../database/level.json');
let place = require('../database/place.json');
let money = require('../database/money.json');

module.exports = async (client, message) => {
  if (message.content === "market") {
    message.reply(`yup, what?`);
  }
  if(!visitor[message.author.id]){
    visitor[message.author.id] = {
      totalvis: 0,
      totalbuyer: 0
    };
  }
  if(!level[message.author.id]){
    level[message.author.id] = {
      level: 1,
      exp: 0
    };
  }
  if(!place[message.author.id]){
    place[message.author.id] = {
      pla: "Hongria"
    };
  }
  if(!money[message.author.id]){
    money[message.author.id] = {
      balance: 20
    };
  }
  if(level[message.author.id].exp > 300) {
    let amount = Math.floor(Math.random() * 60) + 20;
    money[message.author.id].balance = money[message.author.id].balance + amount;
    level[message.author.id].level++;
    level[message.author.id].exp = 0;
    let embed = new MessageEmbed()
      .setTitle(`${message.author.username} Level Up`)
      .addField(`Rewards`, `+ ${amount} Money`)
      .setColor("#E5E5E5")
      .setTimestamp()
    message.channel.send(embed);
  }
  fs.writeFile('./database/visitor.json', JSON.stringify(visitor, null, 2), (err) => {
      if (err) console.log(err);
  });
  fs.writeFile('./database/level.json', JSON.stringify(level, null, 2), (err) => {
      if (err) console.log(err);
  });
  fs.writeFile('./database/place.json', JSON.stringify(place, null, 2), (err) => {
      if (err) console.log(err);
  });
  fs.writeFile('./database/money.json', JSON.stringify(money, null, 2), (err) => {
      if (err) console.log(err);
  });
    if (!message.guild || message.author.bot) return;
    if (message.channel.id === client.config.countChannel) require("../counter")(message, client);
    client.prefix = client.db.fetch(`prefix_${message.guild.id}`) ? client.db.fetch(`prefix_${message.guild.id}`) : client.config.prefix;
    if (!message.content.startsWith(client.prefix)) return;
    let args = message.content.slice(client.prefix.length).trim().split(" ");
    let commandName = args.shift().toLowerCase();
    let command = client.commands.get(commandName) || client.commands.get(client.aliases.get(commandName));
    if (!command) return;
    client.ecoAddUser = message.author.id;
    command.execute(client, message, args);
};

Command.js

const { MessageEmbed } = require("discord.js");
const fs = require('fs');

exports.execute = async (client, message, args) => {
  if (!client.config.admins.includes(message.author.id)) return;
  message.channel.send("**Rebooting system..**").then(m => {
        setTimeout(() => {
            m.edit("**Wait a sec...**").then(ms => {
                setTimeout(() => {
                    ms.edit("**Done.**")
                }, 3000)
            })
        }, 3000);

    })
    
    .then(message => process.exit())
    .then(() => client.login(process.env.TOKEN))
}

exports.help = {
    name: "reboot",
    aliases: ["rb"],
    usage: `reboot`
}

I use Discord.js version 12.5.3, my discord bot status is online, but if I try some command, my bot not send any message but in console, no errors. I used to be able to use this method, but now I want to try to make a discord bot again, and I use the same code without changing anything, but now my bot can’t send any messages



Solution

I turn Privileged Gateway Intents in Discord Developer Portal, and it work!


This Question was asked in StackOverflow by MEF STREAM and Answered by MEF STREAM It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?