最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Discord.js bot reply with slash command - Stack Overflow

matteradmin4PV0评论

I have a working slash mand, which is great. I can use the mand with one input parameter eg /mand string and it will execute the mand. However I am looking to set up a Discord bot that uses that mand in a channel every 5 or so minutes. I can't seem to get the bot to use the mand, any ideas on how to get it to work?

It just displays the string in the channel but the bot doesn't execute the mand.

bot.on('messageCreate', async (msg) => {
    if (msg.content === "!loop") {
        interval = setInterval (function () {
            msg.channel.send("/mand string")
        }, 3 * 1000);
    }
})

I have a working slash mand, which is great. I can use the mand with one input parameter eg /mand string and it will execute the mand. However I am looking to set up a Discord bot that uses that mand in a channel every 5 or so minutes. I can't seem to get the bot to use the mand, any ideas on how to get it to work?

It just displays the string in the channel but the bot doesn't execute the mand.

bot.on('messageCreate', async (msg) => {
    if (msg.content === "!loop") {
        interval = setInterval (function () {
            msg.channel.send("/mand string")
        }, 3 * 1000);
    }
})
Share Improve this question edited Oct 23, 2021 at 13:30 Taku 33.8k12 gold badges78 silver badges87 bronze badges asked Oct 23, 2021 at 5:43 JasonTJasonT 631 silver badge5 bronze badges 3
  • All normal bots ignore messages/mands from other bots so you can't abuse your own bot – MegaMix_Craft Commented Oct 23, 2021 at 5:45
  • Dammit... I want to abuse my own bot lol. Hmm will have to think of a work around – JasonT Commented Oct 23, 2021 at 6:00
  • I don't think bots can see nor run slash mands, whether your own or any other bots'. Your code doesn't work because channel.send can only send text, starting with a slash doesn't turn it into a slash mand call. – Taku Commented Oct 23, 2021 at 7:00
Add a ment  | 

1 Answer 1

Reset to default 5

Bots can only receive Application Command Interactions, not create them. This means your bot won't be able to run other bot's slash mands, click their buttons or use their dropdown menus.

If you have control over the other bot's code, though, you can set it up to listen for messages (not interactions) from your second bot, and run code accordingly.

But be aware: as MegaMix mentioned in their ment, if the bot you want to control isn't yours, you probably won't be able to do that, as it is a best practice to ignore messages from other bots to prevent abuse and infinite loops.

Post a comment

comment list (0)

  1. No comments so far