console.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:Red_Star 作者: medeor413 项目源码 文件源码
def _delete_msg(self, args):
        """
        Deletes the given message.
        Syntax: delete_msg (id)
        """
        try:
            chanstr = args[0]
        except IndexError:
            raise ConsoleCommandSyntaxError("No arguments provided.")
        try:
            id = int(args[1])
            if id < 1:
                raise ValueError
        except ValueError:
            raise ConsoleCommandSyntaxError("Invalid amount.")
        except IndexError:
            raise ConsoleCommandSyntaxError("Missing amount argument.")
        try:
            guild, chan = re.match(r"(\d+).(\d+)", chanstr).group(1, 2)
        except AttributeError:
            raise ConsoleCommandSyntaxError("Invalid indices string.")
        try:
            guild = self.client.guilds[int(guild)]
        except IndexError:
            raise ConsoleCommandSyntaxError("Invalid guild index.")
        try:
            chan = guild.text_channels[int(chan)]
        except IndexError:
            raise ConsoleCommandSyntaxError("Invalid channel index.")
        try:
            msg = chan.get_message(id)
        except NotFound:
            raise ConsoleCommandSyntaxError(f"Message with ID {id} not found.")
        try:
            await msg.delete()
        except Forbidden:
            raise ConsoleCommandSyntaxError("Cannot delete message; no permissions.")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号