Last active
November 18, 2022 20:57
-
-
Save mikeshardmind/e0546cd059b390d2b48636a2641cbccc to your computer and use it in GitHub Desktop.
Because people are running random untrusted code for discord's stupid badge. At least here's a safe way.
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
# Copyright 2022 Michael Hall | |
# LICENSE: Apache License, Version 2.0 : http://www.apache.org/licenses/LICENSE-2.0 | |
from __future__ import annotations | |
import discord | |
import pathlib | |
import random | |
from discord import app_commands | |
class Client(discord.Client): | |
def __init__(self, *, intents: discord.Intents): | |
super().__init__(intents=intents) | |
self.tree = app_commands.CommandTree(self) | |
async def setup_hook(self): | |
f = (Path.cwd() / __file__).with_name("has.sync") | |
if not f.exists(): | |
await self.tree.sync() | |
f.touch() | |
client = Client(intents=discord.Intents.none()) | |
@client.tree.command() | |
async def coinflip(interaction: discord.Interaction): | |
"""Flip a coin.""" | |
await interaction.response.send_message(random.choice(("Heads", "Tails")) | |
if __name__ == "__main__": | |
# If you are sharing this file with anyone, remove the token first. | |
client.run("Token goes here") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment