discord-dota-bot/discord_bot.py
Ching 7bf56375c6 feat(bot.py, utils.py): 修改了消息的格式,更改发送任务循环时间
修改了消息的格式,更改发送任务循环时间

Signed-off-by: Ching <loooching@gmail.com>
2023-09-16 13:03:31 +08:00

32 lines
879 B
Python

import discord
from discord.ext import tasks
import dota
import utils
bot = discord.Bot(proxy='http://127.0.0.1:1235')
@bot.event
async def on_ready():
print(f"We have logged in as {bot.user}")
channel_id = 1152167937852055552
@tasks.loop(minutes=1)
async def send_message(channel):
if utils.is_game_time():
send_message.change_interval(minutes=1)
else:
send_message.change_interval(minutes=15)
matches = dota.get_friends_recent_matches()
for match_ in matches:
data = dota.serialize_match_for_discord(match_)
await channel.send(content=data['content'], embeds=[discord.Embed.from_dict(embed) for embed in data['embeds']])
@bot.event
async def on_ready():
channel = bot.get_channel(channel_id)
send_message.start(channel)
bot.run('MTE1MjE2NTc3NDMwNDIyMzI2Mg.GEi-17.VvuIkRy_cFD9XF6wtTagY95LKEbTxKaxy-FxGw') # 这里替换成你自己的 token