quote command added
Description: Quote a message with his URL - In utils cog - Needed message intents
This commit is contained in:
parent
3184035346
commit
c9b73d8350
|
@ -0,0 +1,53 @@
|
||||||
|
import discord
|
||||||
|
from discord import app_commands
|
||||||
|
from discord.app_commands import Choice
|
||||||
|
from discord.ext import commands
|
||||||
|
import pytz
|
||||||
|
|
||||||
|
from classes.my_cog import MyCog
|
||||||
|
|
||||||
|
|
||||||
|
class Utils(MyCog):
|
||||||
|
def __init__(self, bot):
|
||||||
|
super().__init__(bot)
|
||||||
|
self.bot = bot
|
||||||
|
|
||||||
|
@app_commands.command(name="quote")
|
||||||
|
async def quote(self, interaction: discord.Interaction, link: str):
|
||||||
|
"""
|
||||||
|
Citer un message
|
||||||
|
:param interaction: discord interaction
|
||||||
|
:param link: Lien du message à citer
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
splited_link = link.split("/")
|
||||||
|
|
||||||
|
channel_id = int(splited_link[5])
|
||||||
|
message_id = int(splited_link[6])
|
||||||
|
|
||||||
|
channel = await self.bot.fetch_channel(channel_id)
|
||||||
|
quoted_message = await channel.fetch_message(message_id)
|
||||||
|
|
||||||
|
embed = discord.Embed(
|
||||||
|
description=quoted_message.content,
|
||||||
|
timestamp=quoted_message.created_at.astimezone(pytz.timezone('Europe/Berlin')),
|
||||||
|
color=discord.Color.random()
|
||||||
|
)
|
||||||
|
embed.set_author(name=f"{quoted_message.author.name}",
|
||||||
|
url=link,
|
||||||
|
icon_url=quoted_message.author.display_avatar.url)
|
||||||
|
|
||||||
|
embed.set_footer(text=f"Quoted by {interaction.user.name}")
|
||||||
|
|
||||||
|
await interaction.channel.send(embed=embed)
|
||||||
|
await interaction.response.send_message("Citation opérée avec succès !",
|
||||||
|
ephemeral=True)
|
||||||
|
|
||||||
|
except:
|
||||||
|
await interaction.response.send_message(
|
||||||
|
f"Impossible de citer ce message...\nVérifiez que le lien du message soit valide",
|
||||||
|
ephemeral=True)
|
||||||
|
|
||||||
|
|
||||||
|
async def setup(bot):
|
||||||
|
await bot.add_cog(Utils(bot))
|
1
main.py
1
main.py
|
@ -15,6 +15,7 @@ class MyClient(commands.Bot):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
intents = discord.Intents.none()
|
intents = discord.Intents.none()
|
||||||
intents.guilds = True
|
intents.guilds = True
|
||||||
|
intents.messages = True
|
||||||
super().__init__(intents=intents, command_prefix=".")
|
super().__init__(intents=intents, command_prefix=".")
|
||||||
|
|
||||||
self.MY_GUILD = discord.Object(id=getenv("GUILD_ID"))
|
self.MY_GUILD = discord.Object(id=getenv("GUILD_ID"))
|
||||||
|
|
Loading…
Reference in New Issue