Search code examples
node.jsdiscord.js

Discord app won't reply back when writing basic command


const {Client, GatewayIntentBits } = require("discord.js");

const client = new Client({
    intents:[
      GatewayIntentBits.Guilds,
      GatewayIntentBits.GuildMessages,
      GatewayIntentBits.MessageContent,
      GatewayIntentBits.GuildMembers,
      GatewayIntentBits.DirectMessageTyping,
    ],
});

const prefix = "t!";

client.on('ready', () => {
  console.log(`${client.user.tag} je online :D`);
});

client.on('message ', message => {
  if (message.author.client) return;
  if (message.content.startsWith(settings.prefix)) return;

  if(message.content.startsWith(settings.prefix + "ping")){
    message.reply("Pong!")
  }
  
});

client.login(token);

Im trying to make discord bot but im having hard time making it replay to me. I tried everykind of ways but nothing works so if someone can help me i would be glad.


Solution

  • Here is the working code, just read the documentation and you can fix everything by yourself: https://discord.js.org/#/docs/discord.js/main/general/welcome

    const { Client, GatewayIntentBits } = require("discord.js");
    
    const client = new Client({
        intents:[
          GatewayIntentBits.Guilds,
          GatewayIntentBits.GuildMessages,
          GatewayIntentBits.MessageContent,
          GatewayIntentBits.GuildMembers
        ],
    });
    
    const settings = {
       prefix: 't!',
       token: 'Your bot token'
    };
    
    client.on('ready', () => {
      console.log(`${client.user.tag} je online :D`);
    });
    
    client.on('messageCreate', (message) => {
      if (message.author.bot) return;
      if (!message.content.startsWith(settings.prefix)) return;
    
      if(message.content.startsWith(settings.prefix + "ping")) {
        message.reply({ content: "Pong!" });
      };
      
    });
    
    client.login(settings.token);