code for a basic discord bot with commands hello, ping, and dice
- User
code for a basic discord bot with commands hello, ping, and dice
Assistant
Here is code for a basic Discord bot with hello, ping and dice commands:
import discord from discord.ext import commands client = commands.Bot(command_prefix = '!') @client.event async def on_ready(): print('Bot is ready!') @client.command() async def hello(ctx): await ctx.send('Hello!') @client.command() async def ping(ctx): await ctx.send(f'Pong! {round(client.latency * 1000)}ms') @client.command() async def dice(ctx): await ctx.send(str(random.randint(1, 6))) client.run('your bot token here')This does the following:
- Imports the discord and discord.ext.commands libraries
- Creates a Bot instance with
!as the command prefix - Handles the
on_readyevent to print when the bot is ready - Defines the
!hellocommand to respond with "Hello!" - Defines the
!pingcommand to respond with "Pong!" and the bot latency - Defines the
!dicecommand to roll a random number from 1 to 6 and send that result - Runs the bot using your bot token
The bot token can be obtained by creating a bot application on the Discord Developer Portal. Hope this helps! Let me know if you have any other questions.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.