【发布时间】:2022-09-28 00:59:11
【问题描述】:
我试图编写错误发生时该怎么做的代码,但是当错误实际发生时我总是会得到这个
error found by: gHoSt FaCe#xxxx, in: admins-chat, the message was: <Message id=1023531531035230208 channel=<TextChannel id=1019911370512289802 name=\'admins-chat\' position=22 nsfw=False news=False category_id=1019911233077526578> type=<MessageType.default: 0> author=<Member id=593874348524175405 name=\'gHoSt FaCe\' discriminator=\'2856\' bot=False nick=None guild=<Guild id=744535554036858901 name=\'MJSH21\' shard_id=0 chunked=True member_count=53>> flags=<MessageFlags value=0>>, the error: Member \"test\" not found.
代码:
@client.event
async def on_command_error(ctx, error):
channel = client.get_channel(xxxxxxxx)
await channel.send(f\'error found by: {str(ctx.author)}, in: {str(ctx.channel)}, the message was: {str(ctx.message)}, the error: {str(error)}\')
await ctx.send(f\"An error occured: {str(error)} \")
每次收到消息时,它都会发送很多奇怪的东西 它仍然有效,但我怎样才能删除奇怪的东西,只发送消息而不是所有那些奇怪的东西
进口:
from discord.ext import commands
import discord.member
from dotenv import load_dotenv
import discord
import os
import time
from discord.utils import get
from discord.ext.commands import has_permissions, guild_only, Bot
标签: python discord.py bots message custom-error-handling