I need help making a discord bot

i want to make a discord bot that responds to a certain user with a horse emoji anytime he sends a message tried doing it for the last 4 hours with 0 experience it was painful still didn’t work

Welcome to the forums!

I’d be happy to help. Please send a link to the Repl.

https://replit.com/@yeet45a333/Horse2ElectricBoogaloojs#index.js

thank you

You should start by importing discord, and creating a client. Then go to the Secrets tab and create a new key called TOKEN with the value set to your bot’s token. You can track messages by doing:

client.on("message", (msg) => {
  msg.reply("🐴")
})

Then use

client.login(process.env.TOKEN)

This isn’t the full code as I don’t want to spoon-feed.

2 Likes

how should i go about importing discord?

const discord = require("discord.js")
3 Likes

thank you man i owe you

Oh wait, also note that the bot will infinitely reply to itself. You can fix this by adding

if(message.author.bot) {
  return
}

Or just

if(message.author.bot) return

to make it shorter :slight_smile:

4 Likes

thank you man hopefully after my exams i can dedicate my time here to finally learn coding thank you for all the help

2 Likes

You’re welcome! If you have any more questions, don’t hesitate to reply to me!

1 Like

small question how do i make it respond to a single specific discord user? in reaction form if it’s not any trouble

You must get the specific user’s ID, then use this code

if(!msg.author.id === "THE_USER_ID") {
  return
}

or

if(!msg.author.id === "THE_USER_ID") return

to make it shorter :slight_smile:

If the user’s ID does not match the specific ID, then it’ll return.

Now, if you want the bot to react to the user’s message, you just have to use

msg.react("🐴")

See .react() documentation for more information.

2 Likes

it works for the react part but not the specific ID it reacts to anyone that uses the specified message but it crashes after the first reaction

2 Likes

Could you send the error message?

3 Likes

I FIGURED OUT THE PROBLEM it was the code you gave me to keep it from spamming the horse emote i forgot to remove it when we made it horse react instead of using the emote it’s fixed now thank you

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.