בעיה | discord.py on_message_delete לא תמיד עובד
-
בספרייה discord.py יש את האיוונט on_message_delete הבעיה היא שלפעמים הוא עובד ולפעמים לא כאילו יש לו מצבי רוח כל שאר האיוונטים עובדים חלק למישהו יש פיתרון לזה? (יש לבוט גישות מלאות)
אשמח לעזרה ממש דחוף
-
הקוד:
import nextcord from nextcord.ext import commands class MainLogs(commands.Cog): def __init__(self, client: commands.Bot): self.client = client @commands.Cog.listener() async def on_ready(self): guild = self.client.get_guild(int(open('./data/guild_id', 'r').read())) channel = nextcord.utils.get(guild.channels, id=int(open('./data/logs_channel', 'r').read())) audit_old = guild.audit_logs(limit=1) finish = False async for i in audit_old: audit_old = i while not finish: audit_new = guild.audit_logs(limit=1) async for log in audit_new: audit_new = log if audit_new != audit_old: if audit_new.action == nextcord.AuditLogAction.message_delete: print('Message deleted') audit_old = audit_new def setup(client): client.add_cog(MainLogs(client))
גם הקוד הזה לא עובד:
import nextcord from nextcord.ext import commands import datetime def GetLogsChannel(guild): channel = nextcord.utils.get(guild.channels, id=int(open(r'./data/logs_channel', 'r').read())) return channel class MessageDelete(commands.Cog): def __init__(self, client): self.client = client @commands.Cog.listener('on_message_delete') async def on_message_delete(self, message: nextcord.Message): log_channel = GetLogsChannel(message.guild) audit_logs = await message.guild.audit_logs(limit=1).flatten() for entry in audit_logs: if entry.action == nextcord.AuditLogAction.message_delete: print('message deleted') deleter = entry.user embed = nextcord.Embed(title='Message deleted', description=f'{deleter.mention} Deleted message by {message.author.mention} ' f'at {message.channel.mention}', color=0x0366fc) embed.add_field(name='Message content:', value=message.content) embed.timestamp = datetime.datetime.now() embed.set_footer(text=f'Crazy Party Logs \u200b', icon_url='https://cdn.discordapp.com/attachments/111430432223527' '3287/1142212995460640828/unknown.png') await log_channel.send(embed=embed) def setup(client: commands.Bot): client.add_cog(MessageDelete(client))
-
@Yehuda-1 מהתיעוד:
Called when a message is deleted. If the message is not found in the
internal message cache, then this event will not be called.
Messages might not be in cache if the message is too old
or the client is participating in high traffic guilds.
If this occurs increase the max_messages parameterתנסה...