Skip to content

Commit 6b758e3

Browse files
committed
Ajout de la commande annonce
1 parent 1bd6223 commit 6b758e3

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

code/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ async def on_command_error(interaction, error):
5050

5151
raise error
5252

53-
TOKEN = ""
53+
TOKEN = "OTIxMTQ1MzU1NTYxNzQyMzk2.GHPvKg.Oc1GGhhRCaIrgduhV1oct6uTYZ3WpALrjf-pHM "
5454
print("Launch of the Client...")
5555
client.run(TOKEN)

code/utils.py

+53-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,60 @@
11
import discord
22
from discord import app_commands
33

4+
5+
@app_commands.checks.has_permissions(administrator=True)
6+
7+
@app_commands.rename(channel="salon")
8+
@app_commands.describe(channel="Le salon dans lequel tu veux faire ton annonce.")
9+
10+
@app_commands.rename(title="titre")
11+
@app_commands.describe(title="Le titre que tu veux donner à ton annonce.")
12+
13+
@app_commands.rename(announcement="annonce")
14+
@app_commands.describe(announcement="Ton annonce.")
15+
16+
@app_commands.rename(thumbnail="icone")
17+
@app_commands.describe(thumbnail="L'icône que tu veux donner à ton annonce.")
18+
19+
@app_commands.describe(image="L'image que tu veux donner à ton annonce.")
20+
21+
@app_commands.choices(color=[
22+
app_commands.Choice(name="bleu", value=1),
23+
app_commands.Choice(name="vert", value=2),
24+
app_commands.Choice(name="rouge", value=3)
25+
])
26+
@app_commands.rename(color="couleur")
27+
@app_commands.describe(color="La couleur que tu veux donner à ton message.")
28+
async def announcement_command(interaction: discord.Interaction, channel: discord.TextChannel, title: str,
29+
announcement: str, thumbnail: discord.Attachment = None, image: discord.Attachment = None, color: app_commands.Choice[int] = 1):
30+
"""
31+
Cette commande permet à un administrateur de faire une annonce dans un salon spécifié :
32+
- Paramètre 'channel' : Le salon où l'on veut poster l'annonce;
33+
- Paramètre 'announcement' : L'annonce a faire;
34+
- Paramètre 'thumbnail' (facultatif) : Icône affichée en haut à droite du message de type Embed;
35+
- Paramètre 'image' (facultatif) : Image ajoutée à l'annonce;
36+
- Paramètre 'title' : Titre de l'annonce;
37+
"""
38+
if color.value == 1: color = discord.Color.blue()
39+
elif color.value == 2: color = discord.Color.green()
40+
elif color.value == 3: color = discord.Color.red()
41+
42+
embed = discord.Embed(title=title, description=announcement, color=color)
43+
if thumbnail is not None:
44+
embed.set_thumbnail(url=thumbnail.url)
45+
46+
if image is not None:
47+
embed.set_image(url=image.url)
48+
49+
embed.set_footer(icon_url=interaction.user.avatar.url, text=f"Annonce faite par {interaction.user.name} !")
50+
await channel.send(embed=embed)
51+
52+
validation_embed = discord.Embed(title=":white_check_mark: | Ton annonce à bien été envoyée !", color=discord.Color.green())
53+
validation_embed.set_thumbnail(url="https://cdn3.emoji.gg/emojis/2121-announcement-badge.png")
54+
await interaction.response.send_message(embed=validation_embed, ephemeral=True)
55+
456
# Cette ligne doit se trouver à la fin du fichier !
5-
utils_commands = []
57+
utils_commands = [{'name':'annonce', 'description':'Cette commande permet de créer un message d\'annonce ! (Permission réquise : Administrateur)', 'func':announcement_command}]
658
# Elle sert à ajouter à "l'arbre" des commandes du Bot la commande crée :
759
#
860
# Pour cela il faut y mettre un nouveau dictionnaire et y mettre les clés suivantes avec ce qui leur correspond en paramètre :

0 commit comments

Comments
 (0)