0

I'm following this tutorial: https://www.youtube.com/watch?v=qv24S2L1N0k&t=1s

the bot is working in the terminal, but not on the Discord Server.

bot.js:

require('dotenv').config()

const Discord = require('discord.js')
const client = new Discord.Client()

client.on('ready', () => {
    console.log('Our bot is ready to go!!!')
})

client.login(process.env.BOT_TOKEN)

client.on("message", msg => {
    if(msg.content === 'ping'){
        msg.channel.send("Not tagged")
    }
})

package.json

{
  "name": "bot_development",
  "version": "1.0.0",
  "description": "",
  "main": "bot.js",
  "scripts": {
    "start": "node bot.js",
    "devStart": "nodemon bot.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "discord.js": "^12.5.3",
    "dotenv": "^8.2.0",
    "node": "^16.18.1"
  },
  "devDependencies": {
    "nodemon": "^2.0.20"
  }
}

I've tried with

const client = new Discord.Client({intents: ["GUILDS", "GUILD_MESSAGES"]})

and I've tried "messageCreate" instead of "message", like this:

require('dotenv').config()

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

client.on('ready', () => {
    console.log('Our bot is ready to go!!!')
})

client.login(process.env.BOT_TOKEN)

client.on("messageCreate", msg => {
    if(msg.content === 'ping'){
        msg.channel.send("Not tagged")
    }
})

Is there any problem outside of my code? I've done the rest of the configuration at the dev portal in the tutorial.

LosmiNCL
  • 155
  • 3
  • 21
  • is the bot online in the discord server? – Delano van londen Nov 29 '22 at 09:07
  • Try with client.login at the end of the file – ShadowCrafter_01 Nov 29 '22 at 09:08
  • @Delanovanlonden It is. Has a green circle. I'm running the bot locally, via the terminal, just like in the first part of the tutorial. When When I generated OAuth URL I choose "Bot" and then I checked "send messages" – LosmiNCL Nov 29 '22 at 09:11
  • @ShadowCrafter_01 I've moved the client login line to the end of the file now. The bot is updated live reload, via devStart. But still not responding on the server. Do I need to click it and reinvite after each update or not? – LosmiNCL Nov 29 '22 at 09:13
  • You don't need to reinvite it after each update, but I don't think live reload will work. I would restart it just in case – ShadowCrafter_01 Nov 29 '22 at 09:15
  • @ShadowCrafter_01 I've restarted in the terminal, still not responding – LosmiNCL Nov 29 '22 at 09:18
  • Do you see "Our bot is ready to go!!!" in the console? If so try putting a console.log inside the messageCreate listener but not inside the content check – ShadowCrafter_01 Nov 29 '22 at 09:24
  • @ShadowCrafter_01 Yes, I see "Our bot is ready to go!!!" every time. I've added now console.log() inside messageCreate, after if the body (outside if body). When I test on the discord server by typing a ping message, I don't see any response in the console. Maybe the function is not triggered at all? – LosmiNCL Nov 29 '22 at 09:28
  • I'll have to try it out later – ShadowCrafter_01 Nov 29 '22 at 09:31
  • @ShadowCrafter_01 Update: Sorry, I forgot to write the log message inside the log function. I wrote 'hey' now. so, now when I write ping on the Discord server, I get a response 'hey' in my Console. But I don't get that message on the server – LosmiNCL Nov 29 '22 at 09:53
  • Ok so I guess the check of the message.content doesn't work as you want – ShadowCrafter_01 Nov 29 '22 at 10:40

1 Answers1

-1
client.on("message", msg => {
    if(msg.content === "ping"){

//try msg.reply("pong") if the code below does not work
        msg.channel.send("Not tagged");
    }
})

try changing createMessage to 'message'

  • I've tried both msg.reply and msg.channel.send (inside message listener instead of messageCreate). Still not working, on the server. (on the console it's working). Isn't the "message" listener deprecated? I'm confused about what is better to use, message or messageCreate – LosmiNCL Nov 29 '22 at 09:54
  • can you reply 'Our bot is ready to go!!!!' instead of console logging it, this might. if this works then you can recreate your reply function – Delano van londen Nov 29 '22 at 10:02
  • I needed to enable server member intent and message content intent at Discord developer portal, now it works – LosmiNCL Nov 29 '22 at 11:08
  • okay good that it works now – Delano van londen Nov 29 '22 at 11:08