added 60 sec. report cooldown

This commit is contained in:
Paillat
2023-03-09 16:49:42 +01:00
parent 218bf2aa03
commit 4c87c66add
2 changed files with 25 additions and 11 deletions

View File

@@ -26,4 +26,9 @@ bot.run(discord_token) # run the bot
@bot.event @bot.event
async def on_ready(): async def on_ready():
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="your messages to answer you")) await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="your messages to answer you"))
debug("Bot is ready") debug("Bot is ready")
@bot.event
async def on_application_command_error(ctx, error):
debug(error)
await ctx.respond(error, ephemeral=True)

View File

@@ -1,4 +1,5 @@
import discord import discord
from discord.ext import commands
from config import debug, c, max_uses, cp, conn, connp, webhook_url from config import debug, c, max_uses, cp, conn, connp, webhook_url
import makeprompt as mp import makeprompt as mp
import aiohttp import aiohttp
@@ -18,18 +19,17 @@ class MyModal(discord.ui.Modal):
session = aiohttp.ClientSession() session = aiohttp.ClientSession()
webhook = discord.Webhook.from_url(webhook_url, session=session) webhook = discord.Webhook.from_url(webhook_url, session=session)
embed = discord.Embed(title="Downvote", description=f"Downvote recieved!", color=discord.Color.og_blurple()) embed = discord.Embed(title="Downvote", description=f"Downvote recieved!", color=discord.Color.og_blurple())
embed.add_field(name="Reason", value=self.children[0].value) embed.add_field(name="Reason", value=self.children[0].value, inline=True)
embed.add_field(name="Author", value=self.message.author.mention) embed.add_field(name="Author", value=self.message.author.mention, inline=True)
embed.add_field(name="Channel", value=self.message.channel.name) embed.add_field(name="Channel", value=self.message.channel.name, inline=True)
embed.add_field(name="Guild", value=self.message.guild.name) embed.add_field(name="Guild", value=self.message.guild.name, inline=True)
msgembed = discord.Embed(title="Messages", description=f"Messages history", color=discord.Color.og_blurple())
history = await self.message.channel.history(limit=5).flatten() history = await self.message.channel.history(limit=5).flatten()
for message in history: for msg in history:
msgembed.add_field(name=message.author.name, value=message.content, inline=False) embed.add_field(name="Message", value=msg.content, inline=False)
embeds = [embed, msgembed] await webhook.send(embed=embed)
await webhook.send(embeds=embeds)
except Exception as e: except Exception as e:
debug(e) debug(e)
debug("Error while sending webhook, probably no webhook is set up in the .env file")
class Chat (discord.Cog) : class Chat (discord.Cog) :
@@ -60,6 +60,15 @@ class Chat (discord.Cog) :
@discord.message_command(name="Downvote", description="Downvote a message") @discord.message_command(name="Downvote", description="Downvote a message")
@commands.cooldown(1, 60, commands.BucketType.user)
async def downvote(self, ctx: discord.ApplicationContext, message: discord.Message): async def downvote(self, ctx: discord.ApplicationContext, message: discord.Message):
modal = MyModal(message) modal = MyModal(message)
await ctx.send_modal(modal) await ctx.send_modal(modal)
@downvote.error
async def downvote_error(self, ctx, error):
if isinstance(error, commands.CommandOnCooldown):
await ctx.respond("You are on cooldown !", ephemeral=True)
else:
debug(error)
raise error