Update mod.py (#18)

This commit is contained in:
Ayato (Shahil) 2022-04-12 09:31:35 -07:00 committed by TSR Berry
parent c8a9603bb0
commit 5ee601bda5
No known key found for this signature in database
GPG key ID: 52353C0A4CCA15E2

View file

@ -690,6 +690,57 @@ class Mod(Cog):
await ctx.send("Successfully set bot nickname.")
@commands.guild_only()
@commands.check(check_if_staff)
@commands.command()
async def move(context):
# get the content of the message
content = context.message.content.split(' ')
# if the length is not three the command was used incorrectly
if len(content) != 3 or not content[2].isnumeric():
await context.message.channel.send("Incorrect usage of !move. Example: !move {channel to move to} {number of messages}.")
return
# channel that it is going to be posted to
channelTo = content[1]
# get the number of messages to be moved (including the command message)
numberOfMessages = int(content[2]) + 1
# get a list of the messages
fetchedMessages = await context.channel.history(limit=numberOfMessages).flatten()
# delete all of those messages from the channel
for i in fetchedMessages:
await i.delete()
# invert the list and remove the last message (gets rid of the command message)
fetchedMessages = fetchedMessages[::-1]
fetchedMessages = fetchedMessages[:-1]
# Loop over the messages fetched
for messages in fetchedMessages:
# get the channel object for the server to send to
channelTo = discord.utils.get(messages.guild.channels, name=channelTo)
# if the message is embeded already
if messages.embeds:
# set the embed message to the old embed object
embedMessage = messages.embeds[0]
# else
else:
# Create embed message object and set content to original
embedMessage = discord.Embed(
description = messages.content
)
# set the embed message author to original author
embedMessage.set_author(name=messages.author, icon_url=messages.author.avatar_url)
# if message has attachments add them
if messages.attachments:
for i in messages.attachments:
embedMessage.set_image(url = i.proxy_url)
# Send to the desired channel
await channelTo.send(embed=embedMessage)
async def setup(bot):
await bot.add_cog(Mod(bot))