Answer the question
In order to leave comments, you need to log in
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
Try like this:
@client.event
async def on_message(message):
print(f'[{message.channel}] Сообщение от {message.author}: {message.content}')
{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
@client.event
async def on_message(message):
await client.process_commands(message)
print(f'[{message.channel}] Сообщение от {message.author}: {message.content}')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question