0
votes

I am trying to create something of an application bot. I need the bot to be triggered in a generic channel and then continue the application process in a private DM channel with the applicant.

My issue is this : The bot can have only one on_message function defined. I find it extremely complicated (and inefficient) to check everytime if the on_message was triggered by a message from a DM channel vs the generic channel. Also, makes it difficult to keep track of an applicants answers. I want to check if the following is possible : Have the bot respond to messages from the generic channel as usual. If it receives an application prompt, start a new subprocess (or bot?) that handles the DMs with the applicant separately.

Is the above possible? if not, is there an alternative to handling this in a better way ?

@client.event
async def on_message(message):
    if message.author == client.user:
        return


    if message.channel.type==discord.ChannelType.private:

        await dm_channel.send("Whats your age?") ## Question 2


    elif message.channel.type == discord.ChannelType.text:
    
        if message.content.startswith('$h'):

            member = message.author

            if "apply" in message.content:
                await startApply(member)
            else:
                await message.channel.send('Hello!')
            # await message.reply('Hello!', mention_author=True)


async def startApply(member):

    dm_channel = await member.create_dm()
    await dm_channel.send("Whats your name?") ## Question 1 

I have the above code as of now. I want the startApply function to trigger a new bot/subprocess to handle the DMs with an applicant.

1
You should consider using wait_forAbdulaziz

1 Answers

0
votes

Option 1

Comparatively speaking, a single if check like that is not too much overhead, but there are a few different solutions. First, you could try your hand at slash commands. This is library built as an extension for the discord.py library for slash commands. You could make one that only works in DM's, and then have it run from there with continuous slash commands.

Option 2

Use a webhook to start up a new bot. This is most likely more complicated, as youll have to get a domain or find some sort of free service to catch webhooks. You could use a webhook like this though to 'wake up' a bot and have it chat with the user in dm's.

Option 3 (Recommended)

Create functions that handle the text depending on the channel, and keep that if - elif in there. As i said, one if isn't that bad. If you had functions that are called in your code that handled everything, it actually should be fairly easy to deal with:

@client.event
async def on_message(message):
    if message.author == client.user:
        return

    if message.channel.type==discord.ChannelType.private:
        respondToPrivate(message)

    elif message.channel.type == discord.ChannelType.text:
        repondToText(message)

In terms of keeping track of the data, if this is a smaller personal project, MySQL is great and easy to learn. You can have each function store whatever data needed to the database so that you can have it stored to be looked at / safe in case of bot crash & then it will also be out of memory.