Saltar al contenido

mensaje de error ejemplo de código discord.py

Si encuentras algún detalle que no comprendes puedes dejarlo en la sección de comentarios y te ayudaremos rápidamente.

Ejemplo: errores en discord.py

# This will be a quick example of how to handle errors in discord.py import discord
from discord.ext import commands
# make sure to import these ^# Let's say we have a kick command@client.command()@commands.has_any_role('Admin')asyncdefkick(ctx, member : discord.Member,*, reason=None):await member.kick(reason=reason)await ctx.send('''
Kicked user: 
Reason: '''.format(member, reason))# Okay, so it works. But what if someone does !kick without the arguments# We will get an error. So let's handle that.# I will show 2 ways # Here is the first one. # This way will handle EVERY missing arguments error@client.eventasyncdefon_command_error(ctx, error):ifisinstance(error, commands.MissingRequiredArgument):await ctx.send('Make sure you put the required arguments.')# Now, if someone uses any command and doesn't put the# Required arguments, then this event will occur # Here is the second one# This way will handle one command's error @kick.errorasyncdefkick_error(ctx, error):ifisinstance(error, commands.MissingRequiredArgument):await ctx.send('To use the kick command do: !kick ')# Using this method we can account for all our commands individually # I recommend using this method, however both methods work basically the same# For example if we had a ban command, we could do the same # Doing @ban.error and accounting for that one as well!

Comentarios y puntuaciones del tutorial

Si te ha sido de utilidad nuestro artículo, agradeceríamos que lo compartas con otros entusiastas de la programación y nos ayudes a dar difusión a nuestra información.

¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)



Utiliza Nuestro Buscador

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *