Created
July 12, 2022 03:59
-
-
Save Glowstik-YT/a21b027db38406a263a60e19d3f23e0c to your computer and use it in GitHub Desktop.
a gist for my warn series on yt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from nextcord.ext import commands | |
import nextcord | |
from sqlalchemy import desc | |
from config import TOKEN | |
import asyncio | |
import aiosqlite | |
import datetime | |
bot = commands.Bot(command_prefix='!') | |
@bot.event | |
async def on_ready(): | |
print("Bot is up and ready!") | |
bot.db = await aiosqlite.connect('warns.db') | |
await asyncio.sleep(3) | |
async with bot.db.cursor() as cursor: | |
await cursor.execute("CREATE TABLE IF NOT EXISTS warns(user INTEGER, reason TEXT, time INTEGER, guild INTEGER)") | |
await bot.db.commit() | |
print("Database Ready!") | |
async def addwarn(ctx: commands.Context, reason, user): | |
async with bot.db.cursor() as cursor: | |
await cursor.execute("INSERT INTO warns (user, reason, time, guild) VALUES (?, ?, ?, ?)", (user.id, reason, int(datetime.datetime.now().timestamp()), ctx.guild.id)) | |
print('hi') | |
await bot.db.commit() | |
@bot.command(description="Warns a user") | |
@commands.has_permissions(manage_messages=True) | |
async def warn(ctx: commands.Context, member: nextcord.Member, *, reason: str= "No Reason Provided"): | |
await addwarn(ctx, reason, member) | |
await ctx.send(f"Warned {member.mention} for {reason}") | |
@bot.command(description="Removes a users warning") | |
@commands.has_permissions(manage_guild=True) | |
async def removewarn(ctx: commands.Context, member: nextcord.Member): | |
async with bot.db.cursor() as cursor: | |
await cursor.execute('SELECT reason FROM warns WHERE user = ? AND guild = ?', (member.id, ctx.guild.id)) | |
data = await cursor.fetchone() | |
if data: | |
await cursor.execute('DELETE FROM warns WHERE user = ? AND guild = ?', (member.id, ctx.guild.id)) | |
await ctx.send('deleted users warning') | |
else: | |
await ctx.send('No warnings found!') | |
await bot.db.commit() | |
@bot.command(description="Views a users warning") | |
@commands.has_permissions(manage_messages=True) | |
async def warns(ctx: commands.Context, member: nextcord.Member): | |
async with bot.db.cursor() as cursor: | |
await cursor.execute('SELECT reason, time FROM warns WHERE user = ? AND guild = ?', (member.id, ctx.guild.id)) | |
data = await cursor.fetchall() | |
if data: | |
em = nextcord.Embed(title=f"{member.name}'s Warnings") | |
warnnum = 0 | |
for table in data: | |
warnnum += 1 | |
em.add_field(name=f"Warning {warnnum}", value=f"Reason: {table[0]} | Date Issued: <t:{int(table[1])}:F>") | |
await ctx.send(embed=em) | |
else: | |
await ctx.send('no warnings found!') | |
await bot.db.commit() | |
bot.run(TOKEN) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment