本文整理匯總了Python中discord.ext.commands.DisabledCommand方法的典型用法代碼示例。如果您正苦於以下問題:Python commands.DisabledCommand方法的具體用法?Python commands.DisabledCommand怎麽用?Python commands.DisabledCommand使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類discord.ext.commands
的用法示例。
在下文中一共展示了commands.DisabledCommand方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: on_command_error
# 需要導入模塊: from discord.ext import commands [as 別名]
# 或者: from discord.ext.commands import DisabledCommand [as 別名]
def on_command_error(self, error, ctx):
ignored = (commands.NoPrivateMessage, commands.DisabledCommand, commands.CheckFailure,
commands.CommandNotFound, commands.UserInputError, discord.HTTPException)
error = getattr(error, 'original', error)
if isinstance(error, ignored):
return
if ctx.message.server:
fmt = 'Channel: {0} (ID: {0.id})\nGuild: {1} (ID: {1.id})'
else:
fmt = 'Channel: {0} (ID: {0.id})'
exc = traceback.format_exception(type(error), error, error.__traceback__, chain=False)
description = '```py\n%s\n```' % ''.join(exc)
time = datetime.datetime.utcnow()
name = ctx.command.qualified_name
author = '{0} (ID: {0.id})'.format(ctx.message.author)
location = fmt.format(ctx.message.channel, ctx.message.server)
message = '{0} at {1}: Called by: {2} in {3}. More info: {4}'.format(name, time, author, location, description)
self.bot.logs['discord'].critical(message)
示例2: on_command_error
# 需要導入模塊: from discord.ext import commands [as 別名]
# 或者: from discord.ext.commands import DisabledCommand [as 別名]
def on_command_error(error, ctx):
if isinstance(error, commands.NoPrivateMessage):
await ctx.author.send('This command cannot be used in private messages.')
elif isinstance(error, commands.DisabledCommand):
await ctx.channel.send(':x: Dieser Command wurde deaktiviert')
elif isinstance(error, commands.CommandInvokeError):
if bot.dev:
raise error
else:
embed = discord.Embed(title=':x: Command Error', colour=0x992d22) #Dark Red
embed.add_field(name='Error', value=error)
embed.add_field(name='Guild', value=ctx.guild)
embed.add_field(name='Channel', value=ctx.channel)
embed.add_field(name='User', value=ctx.author)
embed.add_field(name='Message', value=ctx.message.clean_content)
embed.timestamp = datetime.datetime.utcnow()
try:
await bot.AppInfo.owner.send(embed=embed)
except:
pass
示例3: on_command_error
# 需要導入模塊: from discord.ext import commands [as 別名]
# 或者: from discord.ext.commands import DisabledCommand [as 別名]
def on_command_error(ctx, error):
if isinstance(error, commands.CommandNotFound):
return
if isinstance(error, commands.DisabledCommand):
await ctx.send(Language.get("bot.errors.disabled_command", ctx))
return
if isinstance(error, checks.owner_only):
await ctx.send(Language.get("bot.errors.owner_only", ctx))
return
if isinstance(error, checks.dev_only):
await ctx.send(Language.get("bot.errors.dev_only", ctx))
return
if isinstance(error, checks.support_only):
await ctx.send(Language.get("bot.errors.support_only", ctx))
return
if isinstance(error, checks.not_nsfw_channel):
await ctx.send(Language.get("bot.errors.not_nsfw_channel", ctx))
return
if isinstance(error, checks.not_guild_owner):
await ctx.send(Language.get("bot.errors.not_guild_owner", ctx))
return
if isinstance(error, checks.no_permission):
await ctx.send(Language.get("bot.errors.no_permission", ctx))
return
if isinstance(error, commands.NoPrivateMessage):
await ctx.send(Language.get("bot.errors.no_private_message", ctx))
return
if isinstance(ctx.channel, discord.DMChannel):
await ctx.send(Language.get("bot.errors.command_error_dm_channel", ctx))
return
#In case the bot failed to send a message to the channel, the try except pass statement is to prevent another error
try:
await ctx.send(Language.get("bot.errors.command_error", ctx).format(error))
except:
pass
log.error("An error occured while executing the {} command: {}".format(ctx.command.qualified_name, error))
示例4: on_command_error
# 需要導入模塊: from discord.ext import commands [as 別名]
# 或者: from discord.ext.commands import DisabledCommand [as 別名]
def on_command_error(self, context, error):
if isinstance(error, commands.NoPrivateMessage):
await context.author.send(_('This command cannot be used in private messages.'))
elif isinstance(error, commands.DisabledCommand):
message = _('Sorry. This command is disabled and cannot be used.')
try:
await context.author.send(message)
except discord.Forbidden:
await context.send(message)
elif isinstance(error, commands.NotOwner):
logger.error('%s tried to run %s but is not the owner', context.author, context.command.name)
with contextlib.suppress(discord.HTTPException):
await context.try_add_reaction(utils.SUCCESS_EMOJIS[False])
elif isinstance(error, (commands.UserInputError, commands.CheckFailure)):
await context.send(error)
elif (
isinstance(error, commands.CommandInvokeError)
# abort if it's overridden
and
getattr(
type(context.cog),
'cog_command_error',
# treat ones with no cog (e.g. eval'd ones) as being in a cog that did not override
commands.Cog.cog_command_error)
is commands.Cog.cog_command_error
):
if not isinstance(error.original, discord.HTTPException):
logger.error('"%s" caused an exception', context.message.content)
logger.error(''.join(traceback.format_tb(error.original.__traceback__)))
# pylint: disable=logging-format-interpolation
logger.error('{0.__class__.__name__}: {0}'.format(error.original))
await context.send(_('An internal error occurred while trying to run that command.'))
elif isinstance(error.original, discord.Forbidden):
await context.send(_("I'm missing permissions to perform that action."))
### Utility functions
示例5: on_command_error
# 需要導入模塊: from discord.ext import commands [as 別名]
# 或者: from discord.ext.commands import DisabledCommand [as 別名]
def on_command_error(ctx, e):
if hasattr(ctx.cog, 'qualified_name') and ctx.cog.qualified_name == "Admin":
# Admin cog handles the errors locally
return
if SETTINGS.log_errors:
ignored_exceptions = (
commands.MissingRequiredArgument,
commands.CommandNotFound,
commands.DisabledCommand,
commands.BadArgument,
commands.NoPrivateMessage,
commands.CheckFailure,
commands.CommandOnCooldown,
commands.MissingPermissions,
discord.errors.Forbidden,
)
if isinstance(e, ignored_exceptions):
# log warnings
# logger.warning(f'{type(e).__name__}: {e}\n{"".join(traceback.format_tb(e.__traceback__))}')
return
# log error
logger.error(f'{type(e).__name__}: {e}\n{"".join(traceback.format_tb(e.__traceback__))}')
traceback.print_exception(type(e), e, e.__traceback__, file=sys.stderr)
if SETTINGS.msg_errors:
# send discord message for unexpected errors
e = discord.Embed(
title=f"Error With command: {ctx.command.name}",
description=f"```py\n{type(e).__name__}: {str(e)}\n```\n\nContent:{ctx.message.content}"
f"\n\tServer: {ctx.message.server}\n\tChannel: <#{ctx.message.channel}>"
f"\n\tAuthor: <@{ctx.message.author}>",
timestamp=ctx.message.timestamp
)
await ctx.send(bot.owner, embed=e)
# if SETTINGS.mode == 'development':
raise e
示例6: on_command_error
# 需要導入模塊: from discord.ext import commands [as 別名]
# 或者: from discord.ext.commands import DisabledCommand [as 別名]
def on_command_error(self, error, ctx):
if isinstance(error, commands.NoPrivateMessage):
await self.send_message(ctx.message.author, 'This command cannot be used in private messages.')
elif isinstance(error, commands.DisabledCommand):
await self.send_message(ctx.message.author, 'Sorry. This command is disabled and cannot be used.')
elif isinstance(error, commands.CommandInvokeError):
print('In {0.command.qualified_name}:'.format(ctx), file=sys.stderr)
traceback.print_tb(error.original.__traceback__)
print('{0.__class__.__name__}: {0}'.format(error.original), file=sys.stderr)
示例7: on_command_error
# 需要導入模塊: from discord.ext import commands [as 別名]
# 或者: from discord.ext.commands import DisabledCommand [as 別名]
def on_command_error(self, ctx, error):
if hasattr(ctx.command, 'on_error'):
return
ignored = (commands.MissingRequiredArgument, commands.BadArgument, commands.NoPrivateMessage, commands.CheckFailure, commands.CommandNotFound, commands.DisabledCommand, commands.CommandInvokeError, commands.TooManyArguments, commands.UserInputError, commands.CommandOnCooldown, commands.NotOwner, commands.MissingPermissions, commands.BotMissingPermissions)
error = getattr(error, 'original', error)
if isinstance(error, commands.CommandNotFound):
return
elif isinstance(error, commands.BadArgument):
await ctx.send(embed=discord.Embed(color=self.bot.color).set_footer(text=f"Seems like {error}.", icon_url=ctx.author.avatar_url))
elif isinstance(error, commands.MissingRequiredArgument):
await ctx.send(embed=discord.Embed(color=self.bot.color).set_footer(text=f"Seems like {error}.", icon_url=ctx.author.avatar_url))
elif isinstance(error, commands.NoPrivateMessage):
return
elif isinstance(error, commands.CheckFailure):
await ctx.send(embed=discord.Embed(color=self.bot.color).set_footer(text=f"Seems like this command is thought for other users. You can't use it.", icon_url=ctx.author.avatar_url))
elif isinstance(error, commands.DisabledCommand):
await ctx.send(embed=discord.Embed(color=self.bot.color).set_footer(text=f"Seems like this command in disabled.", icon_url=ctx.author.avatar_url))
elif isinstance(error, commands.CommandInvokeError):
await ctx.send(embed=discord.Embed(color=self.bot.color).set_footer(text=f"Seems like something went wrong. Report this issue to the developer.", icon_url=ctx.author.avatar_url))
elif isinstance(error, commands.TooManyArguments):
await ctx.send(embed=discord.Embed(color=self.bot.color).set_footer(text=f"Seems like you gave too many arguments.", icon_url=ctx.author.avatar_url))
elif isinstance(error, commands.UserInputError):
await ctx.send(embed=discord.Embed(color=self.bot.color).set_footer(text=f"Seems like you did something wrong.", icon_url=ctx.author.avatar_url))
elif isinstance(error, commands.CommandOnCooldown):
await ctx.send(embed=discord.Embed(color=self.bot.color).set_footer(text=f"Seems like {error}.", icon_url=ctx.author.avatar_url))
elif isinstance(error, commands.NotOwner):
await ctx.send(embed=discord.Embed(color=self.bot.color).set_footer(text=f"Seems like you do not own this bot.", icon_url=ctx.author.avatar_url))
elif isinstance(error, commands.MissingPermissions):
await ctx.send(embed=discord.Embed(color=self.bot.color).set_footer(text=f"Seems like {error}.", icon_url=ctx.author.avatar_url))
elif isinstance(error, commands.BotMissingPermissions):
await ctx.send(embed=discord.Embed(color=self.bot.color).set_footer(text=f"Seems like {error}.", icon_url=ctx.author.avatar_url))
示例8: on_command_error
# 需要導入模塊: from discord.ext import commands [as 別名]
# 或者: from discord.ext.commands import DisabledCommand [as 別名]
def on_command_error(self, ctx, error):
"""Task when an error occurs."""
if isinstance(error, commands.CommandNotFound):
return logger.info(f"{ctx.author} used {ctx.message.content} "
f"but nothing was found.")
if isinstance(error, commands.MissingRequiredArgument):
logger.info(f"{ctx.author} called {ctx.message.content} and "
f"triggered MissingRequiredArgument error.")
return await ctx.send(f"`{error.param}` is a required argument.")
if isinstance(error, commands.CheckFailure):
logger.info(f"{ctx.author} called {ctx.message.content} and triggered"
f" CheckFailure error.")
return await ctx.send("You do not have permission to use this command!")
if isinstance(error, (commands.UserInputError, commands.BadArgument)):
logger.info(f"{ctx.author} called {ctx.message.content} and triggered"
f" UserInputError error.")
return await ctx.send("Invalid arguments.")
if isinstance(error, commands.CommandOnCooldown):
logger.info(f"{ctx.author} called {ctx.message.content} and"
f" triggered ComamndOnCooldown error.")
return await ctx.send(f"Command is on cooldown!"
f" Please retry after `{error.retry_after}`")
if isinstance(error, commands.BotMissingPermissions):
logger.info(f"{ctx.author} called {ctx.message.content} and triggered"
f" BotMissingPermissions error.")
embed = discord.Embed()
embed.colour = discord.Colour.blue()
title = "The bot lacks the following permissions to execute the command:"
embed.title = title
embed.description = ""
for perm in error.missing_perms:
embed.description += str(perm)
return await ctx.send(embed=embed)
if isinstance(error, commands.DisabledCommand):
logger.info(f"{ctx.author} called {ctx.message.content} and"
f" triggered DisabledCommand error.")
return await ctx.send("The command has been disabled!")
logger.warning(f"{ctx.author} called {ctx.message.content} and"
f" triggered the following error:\n {error}")