discord.py error handling code example
Example 1: errors in discord.py
import discord
from discord.ext import commands
@client.command()
@commands.has_any_role('Admin')
async def kick(ctx, member : discord.Member, *, reason=None):
await member.kick(reason=reason)
await ctx.send('''
Kicked user: {}
Reason: {}'''.format(member, reason))
@client.event
async def on_command_error(ctx, error):
if isinstance(error, commands.MissingRequiredArgument):
await ctx.send('Make sure you put the required arguments.')
@kick.error
async def kick_error(ctx, error):
if isinstance(error, commands.MissingRequiredArgument):
await ctx.send('To use the kick command do: !kick <member>')
Example 2: discordpy error handling
CHECK OUT 'https://realpython.com/lessons/handling-exceptions/'
Example 3: how to add multiple arguments in discord commands rewrite
@bot.command()
async def args(ctx, arg1, arg2):
await bot.say('You sent {} and {}'.format(arg1, arg2))