Home > Enterprise >  Checking What channel a message was sent in, discord.py
Checking What channel a message was sent in, discord.py

Time:02-05

i am making a message logger for fun and i wanted to know if with it saying what was said and who said it if i could see what channel it was in and print it, here is the logger, everything works I just wanted to add specification of channel.

code:

async def on_message(message):
  msg = message.content
  hook.send(f'|{message.author.name}|{msg}')```

CodePudding user response:

async def on_message(message):
  msg = message.content
  channel = message.channel
  hook.send(f'|{message.author.name}|{msg}')

It is all in the docs. If you want to also mention the channel in the a message, then just message.channel.mention

CodePudding user response:

You can answer this question yourself by looking at the documentation for on_message(). The message parameter is a Message object. The documentation for Message lists the attributes which includes channel. If you need the channel's name, then look at the documentation for Channel. Learning how to navigate and read this documentation will be incredibly helpful as you continue to work on your bot.

  •  Tags:  
  • Related