Skip to content

Instantly share code, notes, and snippets.

@miou-gh
Created October 25, 2019 13:50
Show Gist options
  • Save miou-gh/fc9f9525c6a2a4e1ee70070803196c2a to your computer and use it in GitHub Desktop.
Save miou-gh/fc9f9525c6a2a4e1ee70070803196c2a to your computer and use it in GitHub Desktop.
A discord bot for pushing content into other channels.
import re
import io
import discord
import requests
from datetime import datetime
from discord.ext import commands
bot = commands.Bot(command_prefix='bp!')
@bot.command(brief='A command to move a message into another channel.', description='A command to move a message into another channel. (bp!move <message id> <channel>)')
@commands.has_permissions(manage_messages = True)
@commands.bot_has_permissions(manage_messages = True)
async def move(ctx):
content = re.search('bp!move\s*(\d+)\s*to\s*<#(\d+)>\s*', ctx.message.content)
if content == None:
await ctx.send(f'{ctx.message.author.mention}: The command specified is incorrectly formatted - (bp!move <message id> <channel>)', delete_after=5)
return
message_id = int(content.group(1))
message_channel = int(content.group(2))
target_channel = bot.get_channel(message_channel)
target_message = await ctx.fetch_message(message_id)
if target_message == None:
await ctx.send(f'{ctx.message.author.mention}: The message specified does not exist.', delete_after=5)
return
if target_channel == None:
await ctx.send(f'{ctx.message.author.mention}: The channel specified does not exist.', delete_after=5)
return
files = []
for attachment in target_message.attachments:
files.append(discord.File(fp=io.BytesIO(requests.get(attachment.url).content), filename=attachment.filename, spoiler=attachment.is_spoiler()))
embed = discord.Embed(title='The message was originally sent at: %s' % (target_message.created_at.strftime('%Y/%m/%d %I:%M:%S %p')), description='', color=0x00ff00)
embed.set_author(name=target_message.author.name, url=target_message.author.avatar_url, icon_url=target_message.author.avatar_url)
embed.add_field(name='Message', value=target_message.content)
await target_channel.send('', embed=embed, files=files)
await target_message.delete()
await ctx.send(f'{ctx.message.author.mention}: The message was successfully pushed down into {target_channel.mention}', delete_after=5)
await ctx.message.delete()
@bot.event
async def on_ready():
print(f'[Bristol Pusher] Logged in. {bot.user.name} {bot.user.id}')
await bot.change_presence(status=discord.Status.idle, activity=discord.Game("bp!help"))
bot.run('DISCORD_BOT_API_TOKEN')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment