53 lines
1.7 KiB
Python
53 lines
1.7 KiB
Python
import os
|
||
import discord
|
||
from discord.ext import commands
|
||
from openai_interaction.image_recognition_test import image_recognition
|
||
|
||
# Загружаем токен из переменной среды
|
||
TOKEN = os.getenv('SCREAMING_OPOSSUM')
|
||
|
||
# Создаем клиент с префиксом (не обязателен для слэш-команд)
|
||
intents = discord.Intents.default()
|
||
intents.message_content = True
|
||
bot = commands.Bot(command_prefix='!', intents=intents)
|
||
|
||
|
||
# region Bot Stuff
|
||
@bot.event
|
||
async def on_ready():
|
||
print(f'Logged in as {bot.user} (ID: {bot.user.id})')
|
||
print('------')
|
||
try:
|
||
synced = await bot.tree.sync()
|
||
print(f'Synced {len(synced)} command(s).')
|
||
except Exception as e:
|
||
print(f'Failed to sync commands: {e}')
|
||
|
||
|
||
@bot.tree.command(name='hello', description='Screams at you!')
|
||
async def hello_command(interaction: discord.Interaction):
|
||
async with interaction.channel.typing():
|
||
await interaction.response.send_message('AAAAAAAAAAAAAAAAAAAAA!')
|
||
|
||
|
||
@bot.event
|
||
async def on_message(message: discord.Message):
|
||
if message.author == bot.user:
|
||
return
|
||
|
||
if message.attachments and bot.user in message.mentions:
|
||
async with message.channel.typing():
|
||
message_attachments = [
|
||
{'filename': i_attachment.filename, 'url': i_attachment.url} for i_attachment in message.attachments
|
||
]
|
||
await message.channel.send(await image_recognition(message.content, message_attachments))
|
||
|
||
await bot.process_commands(message)
|
||
# endregion
|
||
|
||
|
||
if __name__ == '__main__':
|
||
if TOKEN is None:
|
||
raise RuntimeError('Environment variable SCREAMING_OPOSSUM is not set')
|
||
bot.run(TOKEN)
|