P
P
prostiti2021-07-06 19:02:36
Python
prostiti, 2021-07-06 19:02:36

How to send exact user messages?

I want to make sure that when sending any message, the client bot prints to the console the message that was received from another user. How can I do that? For through the on_message method, I don’t know how to use ctx, *, text

The code works as it should if the message was sent by the user from whom the code knows the token.
Knowing the token result:
User sent a message
Hello, how are you
Console: Hello, how are you
Not knowing the token result:
{blank}

code:

import re
import discord
from discord.ext import commands

client = commands.Bot(intents = discord.Intents.all (), command_prefix=(""), self_bot=True)

@client.event
async def on_ready():
print("Bot is on ( ͡° ͜ʖ ͡°)")

@client.event
async def on_message(message):
print(f"User sent message:\n{message.content}")

client.run( "TOKEN" , bot = False)

PS I want to make a client-bot that will print messages to the console that other users write

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita Mokhovikov, 2021-07-11
@mohovoy

Try like this:

@client.event
async def on_message(message):
     print(f'[{message.channel}] Сообщение от {message.author}: {message.content}')

The output will be like this:
60eb25f14260e877247235.png
{message.channel} - get the name of the channel from which the message is written
{message.author} - get the author of the message
{message.content} - get the text of the message

If you will add other commands, then do the following to the bot:
@client.event
async def on_message(message):
    await client.process_commands(message)
    print(f'[{message.channel}] Сообщение от {message.author}: {message.content}')

This will allow you to use commands and print to the console at the same time

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question