最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论