Write me a skeleton discord bot in python using discord.py
- User
Write me a skeleton discord bot in python using discord.py
- Assistant
Okay! Here is the skeleton of your discord bot, using Python. Please note that Discord requires an API token for your bot, you can get it on the Discord Developer Portal.
import discord from discord.ext import commands bot = commands.Bot(command_prefix='!') @bot.event async def on_ready(): print(f'{bot.user.name} has connected to Discord!') @bot.command() async def hello(ctx): await ctx.send('Hello!') bot.run('YOUR_TOKEN_HERE') - User
How should I store my API token? It's a bad idea to hardcode in the code.
- Assistant
Yes, it is a terrible idea to hard code security tokens in code itself, for two separate but connected reasons:
Technically, the token is a part of the software's configuration, so should not be embedded in the software itself. Additionally, the API token is a secret that should not be shared beyond the individual or organization running the software. There are two things that need consideration:
Since it's a part of configuration. You may want to accept it via a more standard configuration setup, like a configuration file, a configuration service, an environment variable (accessed via
os.environ('APP_DISCORD_TOKEN')), or a command line option. Hopefully your application can use a framework to accept all kinds of configuration. If you do offer the secret directly to be configured via a file, make sure you keep it out of your software version control system (such as using.gitignoreif you are using git for version control), so you don't accidentally share it!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →