0

Here's the code I wrote:

    bot.on('message', (message) => {
    // your messages should go into this array
    const messages = ["honk", "mess with the honk, you get the bonk", "*inhales*   HONKKKK", "*steals your keys*", "*steals your glasses*", "*steals slippers*", "peace was never an option", "*steals knife*", "*rips anti-goose sign down*", "*waddles into blm protests and attempts to chant along*", "never gonna honk you up", "never gonna honk you down", "never gonna honk you up, never gonna honk you down", "https://tenor.com/view/goose-honk-inhale-inhales-untitled-gif-16237480", "https://i.ytimg.com/vi/zqR5pqTjqwM/maxresdefault.jpg", "https://media1.tenor.com/images/320ce00cc388ba92de7757f0458e4ad4/tenor.gif?itemid=16337290", "https://media1.tenor.com/images/6db3d9f7cb1165a0dacd6a9bb4b4af89/tenor.gif?itemid=16627067", "https://nintendowire.com/wp-content/uploads/2019/09/GooseHonk.gif", "https://media1.giphy.com/media/Jp3v0iCuOI3vpCFvf4/giphy.gif?cid=ecf05e4729rv9siv12yp6agxx7tcfhw2pncoghn3cfaqh9yy&rid=giphy.gif", "https://media4.giphy.com/media/xT39CZ1aM1WB0dZwOY/giphy.gif?cid=ecf05e4727230bb427e31469bbd225ca01dbf99c5253f1dc&rid=giphy.gif", "https://tenor.com/view/goose-gif-5452772", "https://tenor.com/view/goose-birds-moves-dance-shake-gif-5453425", "https://tenor.com/view/goose-silly-funny-waddle-funny-walk-gif-16307417", "https://marcus.is-inside.me/asqhvav1.png", "https://cdn.discordapp.com/attachments/737982177765228614/739026340346331166/image0.png", "https://cdn.discordapp.com/attachments/737169801566224434/740210286849687612/image0.jpg", "https://marcus.is-inside.me/hgaNlUNZ.png", "https://cdn.discordapp.com/attachments/740466394361233468/755986396929327236/ZNFMTWerFYngqFZatJG9MM-1200-80.png"]
    const randomMessage = messages[Math.floor(Math.random() * messages.length)];
        if (message.author.bot) return;
        let prefix = 'honk';
        if (message.channel.name === "honk") {
            if (String(message.content.toLowerCase()) == 'honk') {
                chance = Math.floor(Math.random() * 20);
                if (chance == 0) {
                    console.log(`${message.author.tag} hit the jackpot!`)
                    return message.channel.send("h0nk")
                } else {
                    console.log(`${message.author.tag} honked!`)
                    return message.channel.send(randomMessage);
                }
            } else if (String(message.content.toLowerCase()) == 'h0nk'){
                chance = Math.floor(Math.random() * 20);
                if (chance == 0) {
                    console.log(`${message.author.tag} hit the jackpot!`);
                    return message.channel.send('*chuckles* || HONKKKKKKKKKKKKKKKKKKKKKK ||');
                } else {
                    message.delete();
                }
            } else {
                message.delete();
            }

I'm trying to get the following command to work in the #honk channel:

    } else if (String(message.content.toLowerCase()) == ("honkhelp")) {
    console.log(`${message.author.tag} sent honkhelp`)
    const embed = new Discord.MessageEmbed()
        .setTitle("help")
        .setDescription("commands for honkers")
        .setColor("#14ff2c")
        .addField("honk", "well, just say honk!")
        .addField("honkguilds", "check how many guilds the bot is in!")
        .addField("honkpics", "a random goose picture!")
        .addField("requirements", "please make a channel called `#honk` for honkers to work! [please check our troubleshooting page](https://[link])")
        .addField("support server", "[click here](https://discord.gg/GxfQh7H)")
        .addField("other info", "do `honkabout`")
        .setFooter(message.author.tag, message.author.avatarURL({ type: "png", dynamic: true, size: 2048 }))
        .setTimestamp();
    // help embed
    return message.channel.send(embed);

Instead of it responding to the message (and deleting the original message), it deletes the message and doesn't send the embed. How can I make it keep the user message and send the embed?

Source code: https://github.com/inkthought-labs/honk

Thanks for any help!

geneva
  • 27
  • 2
  • 5

1 Answers1

1

Instead of it responding to the message (and deleting the original message), it deletes the message and doesn't send the embed. How can I make it keep the user message and send the embed?

Let's look at the flow of your code

if (message.channel.name === 'honk') {
  // code here
} else if (String(message.content.toLowerCase()) == 'honkhelp')) {
  // send embed help message here
}

Since you are trying to use the 'honkhelp' command in the channel named 'honk', the code will execute the first if and won't enter in any else / else if.

Side note: use === instead of == (you can read about it here)

If you want to prioritize the help message over the usual honk answer, move the block of help in the if and put the rest in the following else if
You can also move this block in an else if after the the if (message.channel.name === "honk")

JackRed
  • 1,188
  • 2
  • 12
  • 28