-1

I want to send a message with my discord bot the simplest way possible, online I'll I've found is stuff that are too complex for me, and I can't get them too work.

require("dotenv").config(); //to start process from .env file
const { Client, GatewayIntentBits } = require('discord.js')
const client = new Client({
    intents: [
        GatewayIntentBits.Guilds, //adds server functionality
        GatewayIntentBits.GuildMessageTyping, //gets messages from our bot.
        GatewayIntentBits.GuildMessages,
        //GatewayIntentBits.GuildEmojisAndStickers,
        //GatewayIntentBits.GuildMembers
    ]
})
client.once("ready", () =>{
    console.log("Bot is online!"); //message when bot is online
})
client.login(process.env.TOKEN);


client.on('message',
function (messages){
    if(messages.content.toLocaleLowerCase()==='hello') 
    messages.channel.send('Hello: ' + messages.author.username); //reply hello word message with senders name
})

If I change my code to this, it still doesn't work:

const {
  Client,
  Partials,
  Collection,
  GatewayIntentBits,
} = require('discord.js');

const client = new Client({
  intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.GuildPresences,
    GatewayIntentBits.GuildMessageReactions,
    GatewayIntentBits.DirectMessages,
    GatewayIntentBits.MessageContent,
  ],
  partials: [
    Partials.Channel,
    Partials.Message,
    Partials.User,
    Partials.GuildMember,
    Partials.Reaction,
  ],
});
Zsolt Meszaros
  • 21,961
  • 19
  • 54
  • 57
monkie-dev
  • 11
  • 2
  • You shouldn't change your code to something completely different from your original question. This is still a duplicate. If you've added the `MessageContent` intent, use `messageContent` instead of the `message` event. It's deprecated. – Zsolt Meszaros Feb 28 '23 at 07:45

1 Answers1

0

Welcome to StackOverflow!

Discord introduced the MessageContent intent a while ago which has to be enabled in your code (via GatewayIntentBits) and also has to be enabled in the Discord Developer Portal as "Privileged Intent" (Can be found under your bot > "Bot" (on the left navigation menu) > Pivileged Gateway Intents > Message Content Intet > enable this option).

ncls.
  • 113
  • 1
  • 7
  • The awnser above didn't work. – monkie-dev Feb 24 '23 at 21:04
  • @monkie-dev Are there any errors? – ncls. Feb 26 '23 at 22:29
  • there are no errors. It just dosen't work. (and yes I've checked bot permissions and checked if it's a discord problem) – monkie-dev Feb 27 '23 at 02:19
  • @monkie-dev What version of Discord.js are you using? I actually should've spotted that earlier but if you're not on v12, you should use the `messageCreate` event since `message` is deprecated. – ncls. Feb 28 '23 at 00:22
  • I'm on v14, and I changed my code. – monkie-dev Feb 28 '23 at 22:23
  • @monkie-dev So does it work now woth `MessageContent` intent and `messageCreate` event? If not, any errors? – ncls. Mar 02 '23 at 02:24
  • I changed the code client.on('MessageContent ', function (messages){ if(messages.content.toLocaleLowerCase()==='hello') messages.channel.send('Hello: ' + messages.author.username); //reply hello word message with senders name }) – monkie-dev Mar 03 '23 at 00:39
  • @monkie-dev It's `client.on('messageCreate', ...` – ncls. Mar 03 '23 at 14:36