Skip to content

Instantly share code, notes, and snippets.

View FlamptX's full-sized avatar

Flampt FlamptX

  • Croatia
View GitHub Profile
@FlamptX
FlamptX / RESTART.md
Last active August 6, 2021 13:37
Basically what I did is that I ran a file restart.py with an argument which was the channel id and then terminated the bot. Then in restart.py I ran the main file (bot.py) with the same argument and then in bot.py I checked if there was an argument, and if there was one, I would fetch the channel with it and send a message saying "Bot restarted!"

Rerun main bot file with a command in discord.py

This is a simple way to restart the bot within itself

Basically what I did is that I ran a file restart.py with an argument which was the channel id and then terminated the bot. Then in restart.py I ran the main file (bot.py) with the same argument and then in bot.py I checked if there was an argument, and if there was one, I would fetch the channel with it and send a message saying "Bot restarted!"

Example bot.py file:

from discord.ext import commands
import argparse
import os
import functools
@FlamptX
FlamptX / swapcase.py
Created July 7, 2021 20:59
The swapcase function takes a string as an argument, then makes a list of it's characters, loops through them and if a character is a digit it will just skip the iteration, but if it's a letter and it's lowercase then it saves it as uppercase and if it's uppercase then it saves it as lowercase. And the end it joins the list into a string and ret…
def swapcase(string: str):
chars = list(string)
i = 0
for x in chars:
if x.isdigit():
continue
if x.islower():
chars[i] = x.upper()
else:
chars[i] = x.lower()
def getRootProperty(source, needle):
returnable = list(source)
sequence = 0
for root in source.items():
for i, j in enumerate(str(root)):
try:
no_numbers = not str(root)[i - 1].isdigit() and not str(root)[i + 1].isdigit() and str(needle) not in root[0]
except IndexError:
no_numbers = True
if j == str(needle) and no_numbers:
@FlamptX
FlamptX / main.py
Last active May 31, 2021 19:56
Get the most dominant color in the member's profile picture and set it as the embed color so it fits with the image.
from discord.ext import commands
import binascii
from PIL import Image
from io import BytesIO
import numpy as np
import scipy.cluster
bot = commands.Bot(command_prefix="!")
@bot.command()