Бот голосование discord.py
Всем привет, в общем нужен бот который каждый день будет отправлять два сообщения, к примеру одно в 15:00, проставлять реакции. Считать их количество и подводить итоги голосования во втором сообщении, допустим в 17:00. Все без сторонних команд, чтобы оно было все автономно. У меня вышел маленький огрызок, так как не обладаю знаниями достаточными, но как-то получается так.
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from apscheduler.triggers.cron import CronTrigger
import discord
from discord.ext import commands
from discord.ext.commands import Bot
from discord.utils import get
from bs4 import BeautifulSoup
bot = commands.Bot(command_prefix = ".")
async def func():
c = bot.get_channel(799262729742319616) # замени потом
msg = ("""@everyone
?️ В 18:00 по МСК игровая сессия.
Голосование за ИЗ, погоду, время и температуру:
? Игровая зона: Los Santos - :LS: : Blaine County - :BC:
? Время 8:00 AM - :Morning: ; 3:00 PM - :Day: ; 8:00 PM - :Evening: ; 1:00 - :Night:
?️ Погода: Ясно- :sun: ;Шторм - :storm: ;Облачно - :Cloudy: ;Пасмурно - :rain:
?️ Температура: 15°С (59 °F)-:Frog: ; 25°C (77 °F)- :Pepega: ; 33°C (91°F)-:pepe_high:
?️ Итоги будут подведены в 17:00 по МСК""")
await c.send(msg)
@bot.command()
async def getmsg(ctx, msgID: int):
msg = await ctx.fetch_message(msgID)
total_count = 0
for r in msg.reactions:
total_count += r.count
print(total_count)
@bot.event
async def on_message(msg):
await msg.add_reaction("<\U0001f1e6>")
await msg.add_reaction("<\U0001f600") # временно пока добавляю обычный эмодзи
@bot.event
async def on_ready():
print("Ready")
#initializing scheduler
scheduler = AsyncIOScheduler()
#sends "текст" to the channel when time hits
scheduler.add_job(func, CronTrigger(year="*", month="*", day="*", hour="15", minute="00", second="00"))
scheduler.add_job(getmsg, CronTrigger(year="*", month="*", day="*", hour="17", minute="00", second="00"))
#starting the scheduler
scheduler.start()
bot.run("ТОКЕН")
Должно получаться что-то типо этого:

Ответы (1 шт):
Автор решения: carter
→ Ссылка
В общем, с божьей помощью я написал это самостоятельно и если кому-то нужен код, то держите. В случае если при голосовании одинаковое число, бот выберет вариант самостоятельно. Пример работы:
КОД:
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from apscheduler.triggers.cron import CronTrigger
from discord.ext import commands
import random
bot = commands.Bot(command_prefix = ".")
async def func():
c = bot.get_channel(ID канала) # замени потом
msg = ("""@everyone
?️ В 18:00 по МСК игровая сессия.
Голосование за ИЗ, погоду, время и температуру:
? Игровая зона: Los Santos - <:15:895358200168206367> : Blaine County - <:seb:895330238249201725>
? Время 8:00 AM - <:10:895358262139039764> ; 3:00 PM - <:11:895358263456067585> ; 8:00 PM - <:12:895358264286511155> ; 1:00 AM - <:1_:895358254396371005>
?️ Погода: Ясно- <:2_:895358262269071441> ;Шторм - <:3_:895358257735016479> ;Облачно - <:4_:895358262185173013> ;Пасмурно - <:5_:895358257047167006>
?️ Температура: 15°С (59 °F)- <:6_:895358259337236512> ; 25°C (77 °F)- <:7_:895358262730424330> ; 33°C (91°F)- <:8_:895358263116304484>
?️ Итоги будут подведены в 17:00 по МСК""")
await c.send(msg)
channel = bot.get_channel(ID КАНАЛА)
message = await channel.fetch_message(channel.last_message_id)
await message.add_reaction('<:15:895358200168206367>') #LS
await message.add_reaction('<:seb:895330238249201725>') #BC
#Игровая Зона
await message.add_reaction('<:10:895358262139039764>')#8am
await message.add_reaction('<:11:895358263456067585>')#3pm
await message.add_reaction('<:12:895358264286511155>')#8PM
await message.add_reaction('<:1_:895358254396371005>')#1am
# ВРЕМЯ
await message.add_reaction('<:2_:895358262269071441>') #Ясно
await message.add_reaction('<:3_:895358257735016479>') #Шторм
await message.add_reaction('<:4_:895358262185173013>') #Облачно
await message.add_reaction('<:5_:895358257047167006>') #Пасмурно
#ПОГОДА
await message.add_reaction('<:6_:895358259337236512>')#15
await message.add_reaction('<:7_:895358262730424330>')#25
await message.add_reaction('<:8_:895358263116304484>')#33
#Температура
async def getmsg():
channel = bot.get_channel(ID КАНАЛА) #!!!
message = await channel.fetch_message(channel.last_message_id)
rizused = False
rtused = False
rwused = False
rtempused = False
time = None
if message.reactions[0].count > message.reactions[1].count:
iz = "Los Santos"
elif message.reactions[1].count > message.reactions[0].count:
iz = "Blaine County"
if message.reactions[0].count == message.reactions[1].count:
izlist = ['Los Santos', 'Blaine County']
riz = random.choice(izlist)
rizused = True
## Время
if message.reactions[2].count > max(message.reactions[3].count, message.reactions[4].count, message.reactions[5].count):
time = "8:00 AM"
if message.reactions[3].count > max(message.reactions[2].count, message.reactions[4].count, message.reactions[5].count):
time = "3:00 PM"
if message.reactions[4].count > max(message.reactions[2].count, message.reactions[3].count, message.reactions[5].count):
time = "8:00 PM"
if message.reactions[5].count > max(message.reactions[2].count, message.reactions[3].count, message.reactions[4].count):
time = "1:00 AM"
if message.reactions[5].count == max(message.reactions[2].count, message.reactions[4].count, message.reactions[3].count) and message.reactions[4].count == max(message.reactions[2].count, message.reactions[3].count, message.reactions[5].count) and message.reactions[3].count == max(message.reactions[2].count, message.reactions[4].count, message.reactions[5].count) and message.reactions[2].count == max(message.reactions[3].count, message.reactions[4].count, message.reactions[5].count):
times = ["3:00 PM","8:00 PM","8:00 AM","1:00 AM"]
rt = random.choice(times)
rtused = True
## Погода
if message.reactions[6].count > max(message.reactions[7].count, message.reactions[8].count, message.reactions[9].count):
weather = "Ясно"
if message.reactions[7].count > max(message.reactions[6].count, message.reactions[8].count, message.reactions[9].count):
weather = "Шторм"
if message.reactions[8].count > max(message.reactions[6].count, message.reactions[7].count, message.reactions[9].count):
weather = "Облачно"
if message.reactions[9].count > max(message.reactions[6].count, message.reactions[7].count, message.reactions[8].count):
weather = "Пасмурно"
if message.reactions[6].count == max(message.reactions[7].count, message.reactions[8].count, message.reactions[9].count) and message.reactions[7].count == max(message.reactions[6].count, message.reactions[8].count, message.reactions[9].count) and message.reactions[8].count == max(message.reactions[6].count, message.reactions[7].count, message.reactions[9].count) and message.reactions[9].count == max(message.reactions[6].count, message.reactions[7].count, message.reactions[8].count):
weathers = ["Ясно","Шторм","Облачно","Пасмурно"]
rw = random.choice(weathers)
rwused = True
## Температура
if message.reactions[10].count > max(message.reactions[11].count, message.reactions[12].count):
temp = "15°С (59 °F)"
if message.reactions[11].count > max(message.reactions[10].count, message.reactions[12].count):
temp = "25°C (77 °F)"
if message.reactions[12].count > max(message.reactions[10].count, message.reactions[11].count):
temp = "33°C (91°F)"
if message.reactions[10].count == max(message.reactions[11].count, message.reactions[12].count) and message.reactions[11].count == max(message.reactions[10].count, message.reactions[12].count) and message.reactions[12].count == max(message.reactions[10].count, message.reactions[11].count):
temps = ["15°С (59 °F)","25°C (77 °F)","33°C (91°F)"]
rtemp = random.choice(temps)
rtempused = True
if rizused == True:
iz = riz
if rtused == True:
time = rt
if rwused == True:
weather = rw
if rtempused == True:
temp = rtemp
mesg = ("""@everyone
В 18.00 по МСК объявлена игровая сессия"""
"""
? Игровая зона — """ + iz +
"""
? Время — """ + time +
"""
☀️ Погода — """ + weather +
"""
?️ Температура — """ + temp +
"""
?️ Удачной сессии""")
await channel.send(mesg)
print("""@everyone
В 18.00 по МСК объявлена игровая сессия"""
"""
? Игровая зона — """ + iz +
"""
? Время — """ + time +
"""
☀️ Погода — """ + weather +
"""
?️ Температура — """ + temp +
"""
?️ Удачной сессии"""
+ str(rtused) + str(rizused) + str(rwused) + str(rtempused))
@bot.event
async def on_ready():
print("Ready")
#initializing scheduler
scheduler = AsyncIOScheduler()
#sends "текст" to the channel when time hits
scheduler.add_job(func, CronTrigger(year="*", month="*", day="*", hour="17", minute="38", second="00"))
scheduler.add_job(getmsg, CronTrigger(year="*", month="*", day="*", hour="17", minute="39", second="00"))
#starting the scheduler
scheduler.start()
bot.run("ТОКЕН")
