def user_spam_check(self, message):
if message.author.id not in self.user_antispam:
self.user_antispam[message.author.id] = []
self.user_antispam[message.author.id].append(message)
if len(self.user_antispam[message.author.id]) == 6: # it can trigger it multiple times if I use >. it can't skip to a number so this should work
await self.bot.add_roles(message.author, self.bot.muted_role)
await self.add_restriction(message.author, "Muted")
msg_user = "You were automatically muted for sending too many messages in a short period of time!\n\nIf you believe this was done in error, send a direct message to one of the staff in {}.".format(self.bot.welcome_channel.mention)
try:
await self.bot.send_message(message.author, msg_user)
except discord.errors.Forbidden:
pass # don't fail in case user has DMs disabled for this server, or blocked the bot
log_msg = "?? **Auto-muted**: {} muted for spamming | {}#{}\n?? __Creation__: {}\n?? __User ID__: {}".format(message.author.mention, message.author.name, message.author.discriminator, message.author.created_at, message.author.id)
embed = discord.Embed(title="Deleted messages", color=discord.Color.gold())
msgs_to_delete = self.user_antispam[message.author.id][:] # clone list so nothing is removed while going through it
for msg in msgs_to_delete:
embed.add_field(name="#"+msg.channel.name, value="\u200b" + msg.content) # added zero-width char to prevent an error with an empty string (lazy workaround)
await self.bot.send_message(self.bot.modlogs_channel, log_msg, embed=embed)
await self.bot.send_message(self.bot.mods_channel, log_msg + "\nSee {} for a list of deleted messages.".format(self.bot.modlogs_channel.mention))
for msg in msgs_to_delete:
try:
await self.bot.delete_message(msg)
except discord.errors.NotFound:
pass # don't fail if the message doesn't exist
await asyncio.sleep(3)
self.user_antispam[message.author.id].remove(message)
try:
if len(self.user_antispam[message.author.id]) == 0:
self.user_antispam.pop(message.author.id)
except KeyError:
pass # if the array doesn't exist, don't raise an error
评论列表
文章目录