def handle_commands(self, ctx: EventContext, message: Message):
"""
Handles commands for a message.
"""
# check bot type
if message.author.user.bot and self.client.bot_type & 8:
return
if message.author.user != self.client.user and self.client.bot_type & 64:
return
if message.guild_id is not None and self.client.bot_type & 32:
return
if message.guild_id is None and self.client.bot_type & 16:
return
# step 1, match the messages
matched = self.message_check(self.client, message)
if inspect.isawaitable(matched):
matched = await matched
if matched is None:
return None
# deconstruct the tuple returned into more useful variables than a single tuple
command_word, tokens = matched
# step 2, create the new commands context
ctx = Context(event_context=ctx, message=message)
ctx.command_name = command_word
ctx.tokens = tokens
ctx.manager = self
# step 3, invoke the context to try and match the command and run it
await ctx.try_invoke()
评论列表
文章目录