def process_payload(self, payload, connection): if payload == Payload.HEARTBEAT: self.send_heartbeat(connection) elif payload == Payload.HEARTBEAT_ACK: self.last_ack = time.time() elif payload == Payload.DISPATCH and payload.event_name == "MESSAGE_CREATE": message = Message.from_payload(payload) self.message_queue.put(message)
async def on_message(self, message: Message) -> None: """ Allow for command chaining using `&&` """ if message.author.bot: return commands = message.content.split(" && ") for command in commands: message.content = command await self.invoke(await self.get_context(message))
def create_discord_message(content, *, channel, **kwargs): default_params = { 'content': content, 'id': 1, 'attachments': [], 'embeds': [], 'edited_timestamp': 0, 'pinned': False, 'mention_everyone': False, 'tts': False, 'mentions': [], 'type': MessageType.default, 'author': create_discord_user() } default_params.update(kwargs) message = Message(state=FakeState(), channel=channel, data=default_params) return message
async def on_message_handler(bot: Bot, message: Message): """Handle an on_message event. First, verify that the bot can respond in the given channel. Then remove any spaces after the prefix. This would normally be achieved by using a callable prefix, but the Discord.py API does not support the use of spaces after symbols, only alphanumeric characters. This is a workaround. """ try: if Config.POM_CHANNEL_NAMES: if message.channel.name not in Config.POM_CHANNEL_NAMES: return except AttributeError: if message.guild is None and not Debug.RESPOND_TO_DM: return if message.content.startswith(Config.PREFIX + " "): message.content = "".join(message.content.split(" ", 1)) await bot.process_commands(message)
async def handle_message_command(self, ctx: Context): if ctx.command_name not in self.all_commands: raise CommandNotFound(f'Command {ctx.command_name} was not found') command = self.all_commands[ctx.command_name] if command.guild_ids is not None and ctx.guild_id not in command.guild_ids: raise CommandNotFound( f'Command {ctx.command_name} was not found in guild {ctx.guild_id}' ) message = Message(state=self._connection, channel=ctx.channel, data=list( ctx._data['resolved']['messages'].values())[0]) ctx.args = {'message': message} self.dispatch('command', ctx) try: if ctx.cog is None: return await ctx.command.callback(ctx, message=message) return await ctx.command.callback(ctx.cog, ctx, message=message) except Exception as exc: return await ctx.command.dispatch_error(ctx, exc) finally: self.dispatch('command_completion', ctx)
async def on_message(self, msg: Message): # if the message doesn't starts with the prefix or is sent by a bot, ignore it if msg.author.bot: return await self.module.handleEvent( 'message', message=msg ) if not msg.content.startswith(self.prefix): return msg.content = msg.content.replace(self.prefix, '', 1) cmd = msg.content.split(' ') print(f'command: {cmd[0]}, parameters: {cmd[ 1:len(cmd) ] if len(cmd) > 1 else None}, issuer: {msg.author.name}') if msg.content.startswith('reload'): await self.reload(msg) elif msg.content.startswith('module'): await self.module.mhandle(msg) else: await self.handleCommand(msg) await self.module.handleEvent( 'command', message= msg )