Skip to content

Instantly share code, notes, and snippets.

@Glowstik-YT
Created July 8, 2022 03:40
Show Gist options
  • Save Glowstik-YT/b065a6e55c4e99e9ab0b8f0f1449c54b to your computer and use it in GitHub Desktop.
Save Glowstik-YT/b065a6e55c4e99e9ab0b8f0f1449c54b to your computer and use it in GitHub Desktop.
import discord
from discord.ext import commands
import aiosqlite
from config import TOKEN
import asyncio
bot = commands.Bot(command_prefix='!', intents = discord.Intents.all())
@bot.event
async def on_ready():
print("Bot is up and ready!")
setattr(bot, "db", await aiosqlite.connect('starboard.db'))
await asyncio.sleep(2)
async with bot.db.cursor() as cursor:
await cursor.execute("CREATE TABLE IF NOT EXISTS starSetup (starLimit INTEGER, channel INTEGER, guild INTEGER)")
await bot.db.commit()
@bot.event
async def on_raw_reaction_add(payload):
emoji = payload.emoji
guild = bot.get_guild(payload.guild_id)
channel = await guild.fetch_channel(payload.channel_id)
message = await channel.fetch_message(payload.message_id)
if emoji.name == "⭐":
async with bot.db.cursor() as cursor:
await cursor.execute("SELECT starLimit, channel FROM starSetup WHERE guild = ?", (guild.id,))
data = await cursor.fetchone()
if data:
starData = data[0]
channelData = await guild.fetch_channel(data[1])
for reaction in message.reactions:
if reaction.emoji == "⭐":
if reaction.count >= starData:
embed = discord.Embed(title="New Starboard Message", description=f"{message.content}")
try:
embed.set_image(url=message.attachments[0].url)
except:
pass
embed.set_author(name="Message Link", url=message.jump_url, icon_url=message.author.avatar.url)
embed.set_footer(text=f"Message ID: {message.id} | Author: {message.author.name}")
await channelData.send(embed=embed)
@bot.group()
async def setup(ctx):
if ctx.invoked_subcommand is None:
return await ctx.send("That subcommand does not exist!")
@setup.command()
@commands.has_permissions(manage_guild=True)
async def channel(ctx, channel: discord.TextChannel):
async with bot.db.cursor() as cursor:
await cursor.execute("SELECT channel FROM starSetup WHERE guild = ?", (ctx.guild.id,))
channelData = await cursor.fetchone()
if channelData:
channelData = channelData[0]
if channelData == channel.id:
return await ctx.send("That channel is already setup!")
await cursor.execute("UPDATE starSetup SET channel = ? WHERE guild = ?", (channel.id, ctx.guild.id,))
await ctx.send(f"{channel.mention} is now the starboard channel!")
else:
await cursor.execute("INSERT INTO starSetup VALUES (?, ?, ?)", (5, channel.id, ctx.guild.id,))
await ctx.send(f"{channel.mention} is now the starboard channel!")
await bot.db.commit()
@setup.command()
@commands.has_permissions(manage_guild=True)
async def stars(ctx, star: int):
async with bot.db.cursor() as cursor:
await cursor.execute("SELECT starLimit FROM starSetup WHERE guild = ?", (ctx.guild.id,))
starData = await cursor.fetchone()
if starData:
starData = starData[0]
if starData == star:
return await ctx.send("That is already the star limit!")
await cursor.execute("UPDATE starSetup SET starLimit = ? WHERE guild = ?", (star, ctx.guild.id,))
await ctx.send(f"{star} is now the star limit!")
else:
await cursor.execute("INSERT INTO starSetup VALUES (?, ?, ?)", (star, 0, ctx.guild.id,))
await ctx.send(f"{star} is now the star limit!")
await bot.db.commit()
@bot.event
async def on_command_error(ctx, error):
em = discord.Embed(title="Error", description=f"```{error}```")
await ctx.send(embed=em, delete_after=90)
return
bot.run(TOKEN)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment