import discord
from discord.ext import commands
# Create an instance of the bot
bot = commands.Bot(command_prefix='!')
# Event triggered when the bot is ready
@bot.event
async def on_ready():
print(f'Logged in as {bot.user.name}')
# Event triggered when a command is invoked
@bot.command()
async def hello(ctx):
await ctx.send('Hello, World!')
# Event triggered when a command is not found or an error occurs in a command
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, commands.CommandNotFound):
await ctx.send('Invalid command. Please check the command and try again.')
else:
await ctx.send(f'An error occurred: {str(error)}')
# Replace YOUR_BOT_TOKEN with your actual Discord bot token
bot.run('YOUR_BOT_TOKEN')