Lena
Lena

Reputation: 1

Getting content from a dm in discord.py

So I want to know if it is possible, that a bot gets the content sent to it in a dm and send that in a specifyed channel on a server. So basically you dm the bot the word "test" and the bots sends the word in a channel of a server

Upvotes: 0

Views: 956

Answers (3)

Ansh Tyagi
Ansh Tyagi

Reputation: 120

@bot.event:
async on_message(message):
    if message.DMChannel:
         # define channel and send message to channel.

You can also refer to DOCS.

Upvotes: 0

J Muzhen
J Muzhen

Reputation: 352

Yes, this is possible:

  • First, we use the on_message() event to detect when a message is sent.
  • We then check if the message is sent in a DM.
  • If so, we will send a message to a specific channel.

Here is one way you can implement it:

# import ...

bot = discord.Bot(...)

@bot.event
async def on_message(message):
    # check if it's
    if isinstance(message.channel, discord.DMChannel):
        # get the channel from ID
        channel = client.get_channel(CHANNEL_ID)  # put channel ID here

        await channel.send("test")   # whatever you want to send

Upvotes: 0

Andrew
Andrew

Reputation: 96

Yes, it is possible for a bot to receive a direct message and then repost the message in a specified channel on a server. This can be done using the Discord API.

You can do the following:

  1. Create a Discord bot and add it to your server. You can do this using the Discord developer portal.

  2. Use the Discord API to listen for messages sent to the bot in a DM. You can do this using the message event and the DMChannel class in the Discord API.

  3. When the bot receives a DM, use the Discord API to repost the message in the specified channel on the server. You can do this using the send method of the TextChannel class in the Discord API.

Upvotes: 1

Related Questions