#Responsive bot command

1 messages · Page 1 of 1 (latest)

carmine wren
#

Hello,

I am new to coding and especially to coding using the discord library. I have already managed to make a bot connect to my server and react to certain '/' commands. However, I can't seem to find out how I can make a command which responds to certain messages which contain a certain string. Could someone guide me with finding this out?

vocal cedarBOT
#

Hey! Once your issue is solved, press the button below to close this thread!

thin minnow
# carmine wren Hello, I am new to coding and especially to coding using the discord library. I...

You can use the bot.listen() decorator with on_message_create like this:

import interactions
from interactions import Client, Intents
from TOKEN import TOKEN

# Bot client (Intents.ALL for ease of use)
bot = Client(intents=Intents.ALL, send_command_tracebacks=False)


@bot.listen()
async def on_message_create(event: interactions.events.MessageCreate):
    if "trigger string" in event.message.content:
        await event.message.reply("You triggered me!")


bot.start(TOKEN)
tepid forge
#

just remember to enable the correct intents

vocal cedarBOT
#

Did you try to read a message but to your surprise it was an empty string? Or you saw a message telling you that the message content is disabled and you want to enable it?

Here is how you enable the message content intent in Discord:

  1. Go to the Discord developer portal.
  2. Select your application.
  3. In the "Bot" tab, go to the "Privileged Gateway Intents" category and scroll down to "Message Content Intent".
  4. Enable the toggle.
    • If your bot is verified or in more than 100 servers, you need to apply for the intent in order to toggle it.

But wait! You aren't done yet!
You need to add the intent in your client as well:

client = interactions.Client(..., intents=interactions.Intents.DEFAULT | interactions.Intents.MESSAGE_CONTENT)  # specifically message content, not just messages

Your bot can now receive message contents!