Build me a basic discord bot.
- User
Build me a basic discord bot.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Build me a basic discord bot.
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Creating a basic Discord bot involves several steps. Below is a simple guide to building a Discord bot using Python and the discord.py library. This bot will respond to a few basic commands like !hello and !ping.
python -m venv venv
venv\Scripts\activate
source venv/bin/activate
discord.py library:
pip install discord.py
Create a file named bot.py and add the following code:
import discord
from discord.ext import commands
# Replace 'YOUR_BOT_TOKEN' with the token you copied from the Discord Developer Portal
TOKEN = 'YOUR_BOT_TOKEN'
# Set up the bot with a command prefix
bot = commands.Bot(command_prefix='!')
# Event: When the bot is ready
@bot.event
async def on_ready():
print(f'Logged in as {bot.user.name} ({bot.user.id})')
# Command: Respond to !hello
@bot.command()
async def hello(ctx):
await ctx.send(f'Hello, {ctx.author.mention}!')
# Command: Respond to !ping
@bot.command()
async def ping(ctx):
await ctx.send('Pong!')
# Run the bot
bot.run(TOKEN)
bot scope and the Send Messages permission.In your terminal, navigate to the directory containing bot.py and run:
python bot.py
Your bot should now be online and responding to !hello and !ping commands in your Discord server.
!hello in a channel where the bot is present.Hello, @Username!!ping.Pong!This is a basic bot, but you can expand its functionality by adding more commands, event listeners, and integrating with other APIs. Happy coding!