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.")
评论列表
文章目录