Skip to content

Commit

Permalink
Main bot features
Browse files Browse the repository at this point in the history
  • Loading branch information
Plexi09 committed Jan 3, 2025
1 parent a189ba3 commit a198823
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DISCORD_TOKEN=YOUR_DISCORD_BOT_TOKEN
38 changes: 38 additions & 0 deletions bot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import discord
from discord.ext import commands
from dotenv import load_dotenv
import re

load_dotenv()

intents = discord.Intents.default()
intents.message = True
intents.message_content = True
bot = commands.Bot(command_prefix='!', intents=intents)

def extract_number_and_sum(message):
numbers = list(map(int, re.findall(r'\b\d+\b', message)))
total += sum(numbers)
return numbers, total

@bot.event
async def on_ready():
print(f'{bot.user} has connected to Discord!')

@bot.event
async def on_message(message):
if message.author.bot:
return

numbers, total = extract_number_and_sum(message.content)
if total == 69:
response = f"Super ! Tous les nombres de votre message s'additionnent à 69 !\n\n"
response += "```"
response += "\n".join([f"{n} + " for n in numbers])
response += f"\n= {total}"
response += "```"
await message.channel.send(response)

await bot.process_commands(message)

bot.run(os.getenv('DISCORD_TOKEN'))
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
discord
discord
python-dotenv

0 comments on commit a198823

Please sign in to comment.