Skip to content

Instantly share code, notes, and snippets.

@mishl-dev
Forked from Zomatree/onelinebot.py
Last active July 7, 2023 12:45
Show Gist options
  • Save mishl-dev/6a52985c4e2b8783594898f83f4e9c17 to your computer and use it in GitHub Desktop.
Save mishl-dev/6a52985c4e2b8783594898f83f4e9c17 to your computer and use it in GitHub Desktop.
import logging
import asyncio
import sqlite3
import random
import math
import re
from discord.ext import commands
logging.basicConfig(level=logging.INFO)
bot = commands.Bot(command_prefix=config.prefix, help_command=commands.MinimalHelpCommand())
@bot.event
async def on_ready():
print("Ready!")
@bot.command(name="hello")
async def hello(ctx):
await ctx.send("hello world")
@bot.command(name="mention")
async def mention(ctx, user: discord.Member):
await ctx.send(user.mention)
@bot.command(name="8ball")
async def eight_ball(ctx, *, args):
await ctx.send(random.choice(["yes", "no", "idk", "shrug"]))
@bot.command(name="quad")
async def quadratic_equation(ctx, *, args):
match = re.match(regex, args)
solution = (
(-int(match[2]) + math.sqrt((int(match[2]) ** 2) - 4 * int(match[1]) * int(match[3]))) / (2 * int(match[1])),
(-int(match[2]) - math.sqrt((int(match[2]) ** 2) - 4 * int(match[1]) * int(match[3]))) / (2 * int(match[1]))
)
await ctx.send(solution)
@bot.command(name="purge")
async def purge(ctx, amount: int):
await bot.loop.create_task(ctx.channel.purge(limit=amount + 1))
await ctx.send(f"purged {amount}", delete_after=10)
@bot.command(name="join")
async def join(ctx, *, channel=None):
channel = channel or ctx.author.voice.channel
if ctx.voice_client is not None:
await ctx.voice_client.move_to(channel)
else:
await channel.connect()
@bot.command(name="play")
async def play(ctx, *, url):
if ctx.author.voice:
if ctx.voice_client is None:
await ctx.author.voice.channel.connect()
else:
if ctx.voice_client.is_playing():
ctx.voice_client.stop()
else:
await ctx.send("You are not connected to a voice channel.")
player = YTDLSource.from_url(url, loop=bot.loop, stream=True)[-1]
ctx.voice_client.play(player, after=lambda e: print('Player error: %s' % e) if e else None)
await ctx.send('Now playing: {}'.format(player.title))
@bot.command(name="volume")
async def volume(ctx, volume):
if ctx.voice_client is not None:
ctx.voice_client.source.volume = int(volume) / 100
await ctx.send("Changed volume to {}%".format(volume))
else:
await ctx.send("Not connected to a voice channel.")
@bot.command(name="stop")
async def stop(ctx):
ctx.voice_client.disconnect()
@bot.group(name="todo", invoke_without_command=True)
async def todo(ctx):
await ctx.send_help(ctx.command)
@todo.command(name="add")
async def add_todo(ctx, *, message):
cur = bot.db.cursor()
cur.execute("""INSERT INTO "todo" VALUES (?, ?)""", (ctx.author.id, message))
bot.db.commit()
await ctx.send(f"Added {message} to your todo list.")
@todo.command(name="list")
async def list_todo(ctx):
query_result = bot.db.cursor().execute("""SELECT Message FROM todo WHERE MemberID=?""", (ctx.author.id,))
todo_list = "\n".join([f"{i}. {x[0]}" for i, x in enumerate(query_result, 1)])
embed = discord.Embed(description=todo_list)
embed.set_author(name=str(ctx.author), icon_url=str(ctx.author.avatar_url_as(format="jpg", static_format="jpg")))
await ctx.send(embed=embed)
bot.run(config.token)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment