我一直在使用www.example.com v2.2.3和Python v3.11.3制作一个discord botdiscord.py,最近我制作了一个purge命令。一旦加载在我的测试服务器一切正常,现在当我尝试在我的其他服务器它的工作可能一次或两次,但现在它只是抛出我的错误消息。我已经看过了,看了一些教程,但我似乎不能得到它的权利。
当我使用命令时,明显的意图是清除/清除消息。正如所说,它在我的测试服务器上工作,只是在我的其他服务器上不工作,这很奇怪。注意,我是Python的新手,所以我确实期望在相当早的时候遇到bug,并且很高兴能够修复它们。这是我的clean message方法。
async def clean_message(self, interaction: Interaction, amount: int, check: Callable) -> Any:
if isinstance((channel := interaction.channel), (CategoryChannel, ForumChannel, PartialMessageable)):
return
assert channel is not None
try:
msgs = [
m async for m in channel.history(
limit=300,
before=Object(id=interaction.id),
after=None
) if check(m) == True and UTC.localize((datetime.now() - timedelta(days=365))) <= m.created_at # default 14
][:amount]
await channel.delete_messages(msgs)
except Exception as e:
msg = await self.bot.error(
f"I'm sorry, I am unable to purge messages in **{channel}**!", interaction
)
if msg:
await msg.delete(delay=5)
else:
if len(msgs) < 1:
msg = await self.bot.error(
f"No messages found in **{channel}**!", interaction
)
if msg:
await msg.delete(delay=5)
else:
msg = await self.bot.success(
f"Succesfully purged **{len(msgs)}** messages from **{channel}**!", interaction
)
if msg:
await msg.delete(delay=5)
它由这里的purge命令调用。
@app_commands.command(
name='purge',
description="Purges messages in channel"
)
@app_commands.default_permissions(manage_messages=True)
@app_commands.describe(
amount='Amount of messages to purge (Default: 20)',
user='Only purge messages by user',
content='Only purge messages by content'
)
async def purge_command(self, interaction: Interaction, amount: Optional[int], user: Optional[User], content: Optional[str]):
if not amount:
amount = 20
if amount < 1:
return await self.bot.error("Can't purge messages! Amount too small!", interaction)
if amount > 150:
return await self.bot.error("Can't purge messages! Amount too Large!", interaction)
if user == None and content == None:
def check(x): return x.pinned == False
else:
if user != None and content != None:
def check(x): return x.author.id == user.id and x.content.lower(
) == content.lower() and x.pinned == False
elif user != None and content == None:
def check(x): return x.author.id == user.id and x.pinned == False
else:
assert content is not None
def check(x): return x.conetent.lower(
) == content.lower() and x.pinned == False
await interaction.response.defer()
await self.clean_message(
interaction=interaction,
amount=amount,
check=check
)
1条答案
按热度按时间ndh0cuux1#
好吧,我才意识到我有多蠢.我已经忘记了我是搞砸了最大清除消息和范围限制。在365天的范围内,清除邮件的最大数量设置为300。简单的错误,花了四个小时才修好。我所要做的就是把消息上限提高到比它更高的水平,并减少范围。