Mexican Taco
Mexican Taco

Reputation: 7

How to detect if someone is wrote something discord.py

I want the bot to check whether someone typed a message in any channel in my discord and then if it detects that the bot did type something I want it to say something, any idea on how to check if someone typed something?

Upvotes: 0

Views: 1391

Answers (1)

Quessts
Quessts

Reputation: 440

After reading the discord docs I found this:

import discord

class MyClient(discord.Client):
    async def on_ready(self):
        print('Logged in as')
        print(self.user.name)
        print(self.user.id)
        print('------')

    async def on_message(self, message):
        # we do not want the bot to reply to itself
        if message.author.id == self.user.id:
            return

        if message.content.startswith('!hello'):
            await message.reply('Hello!', mention_author=True)

client = MyClient()
client.run('token')

Just replace token with your bots token. The rest should be self-explanatory.

Edit:

To detect a specific role you can do something like this:

if message.content.startswith('!hello'):
            if premium_subscriber_role:
                        await message.reply('Hello!', mention_author=True)

This will check if the user has the server booster role and if the user does then the bot will reply with "Hello! @username".

Upvotes: 1

Related Questions