on_message()
?on_message
?Example:
# func.py
class function(self):
async def a(self, ctx):
# content here
# bot.py
class Bot(self, commands.Bot):
async def on_message(self, message):
# make a() run here
on_message
, by getting it with get_context(message)
.get_context
, but just using the message
in on_message
should be suitable for most tasks as it's similar to ctx
and you can get all info almost the same way ( discord.message in the documentation ). Message
is just like ctx.message
. Using message
parameter in on_message()
:
class Bot(self, commands.Bot):
async def on_message(self, message):
print(message.author) #prints author of the message
await message.channel.send("Hello") #sends Hello to the channel (same result as with ctx.send)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.