-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdraftbot.py
More file actions
33 lines (25 loc) · 1.17 KB
/
draftbot.py
File metadata and controls
33 lines (25 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import os
import discord
from discord.ext import commands
from Levenshtein import distance
intents = discord.Intents.default()
intents.messages = True
intents.guilds = True
intents.message_content = True # Add this line to enable the message content intent
intents.presences = True # Add this line to enable the presence intent
intents.members = True # Add this line to enable the server members intent
bot = commands.Bot(command_prefix='/', intents=intents)
# Directory containing the map images
MAP_DIRECTORY = './map_images'
# Read the token from the file
with open("../discord_token", "r") as token_file:
token = token_file.readline().strip()
@bot.command(name='draft')
async def draft(ctx, *, map_name):
# Get a list of all image files in the directory
image_files = [f for f in os.listdir(MAP_DIRECTORY) if f.endswith('.png') or f.endswith('.jpg')]
# Find the image with the closest match using Levenshtein distance
closest_match = min(image_files, key=lambda x: distance(map_name.lower(), os.path.splitext(x)[0].lower()))
# Send the closest matching image
await ctx.send(file=discord.File(os.path.join(MAP_DIRECTORY, closest_match)))
bot.run(token)