Search code examples
pythondiscorddiscord.pybots

Discord.py Translate message contents from Channel to Specific User ID's DMS


I am working on a Discord Bot that if the Prefix (In this case, $) is called, the entire following message is sent to a User's Direct Messages. (user id removed for security)

async def on_message(message):
 if message.content.startswith('$ '):
      CONTENT = message.content
      async def sendDm():
         user = await client.fetch_user("USERID")
         await user.send(CONTENT)

However, upon doing this, The bot is unresponsive. I would like to know why this is happening, and what is wrong with my code.


Solution

  • I got assistance from the Discord.py Discord.

    @client.event
    async def on_message(message):
        if message.content and message.content.startswith("$") and not message.author.bot:
            user = await client.fetch_user(user_id)
            await user.send(message.content)