Kaiasaurin / Python-Projects

Simple projects I made in python (With 0 Keys)
https://python-projects-eight.vercel.app
Apache License 2.0
1 stars 0 forks source link

Discord Bot #1

Open Kaiasaurin opened 2 months ago

Kaiasaurin commented 2 months ago

Creating new key for every user based on user id

Jitroy45 commented 1 month ago
import discord
from discord.ext import commands
import hashlib

bot = commands.Bot(command_prefix='!')

def generate_key(user_id: int) -> str:
    # Use SHA-256 to create a unique hash based on the user ID
    key = hashlib.sha256(str(user_id).encode()).hexdigest()
    return key

@bot.command()
async def getkey(ctx):
    user_id = ctx.author.id
    key = generate_key(user_id)
    await ctx.author.send(f"Your unique key is: {key}")

bot.run('YOUR_BOT_TOKEN')