我们如何在特定日期和时间在 discord.py 中发送消息

时间:2021-04-25 17:55:44

标签: discord.py

我正在创建一个发送特定事件提醒的机器人。比方说,我们有一个将于 2021 年 4 月 28 日 (01) 下午 3:30 发生的事件。

我希望我的机器人在那个日期和时间发送一条消息,即 28/04/2021 和下午 3:30。

请帮帮我。

2 个答案:

答案 0 :(得分:0)

我找到了类似的答案。

这对你有帮助吗? https://stackoverflow.com/a/63659761/14141072

如果仍有问题,请询问我,我会发布我的版本。 :)

谢谢! :D

答案 1 :(得分:0)

我正在寻找像你一样的提醒代码,但我没有找到任何东西,但经过几天的搜索,我找到了一个代码并为我的机器人编辑了它并且它的工作良好,我会在这里分享。

这样做:

import discord
from discord.ext import commands, tasks
import asyncio
import datetime
from datetime import date


time = datetime.datetime.now()
today = date.today()

remtime = today.strftime("%d/%m/%Y")

client = commands.Bot(command_prefix="/")


async def timer():
    await client.wait_until_ready()
    channel = client.get_channel(Channel Id Here)
    msg_sent = False
    
    while True:
#15 = 3pm  in 24 hour format
        if time.hour == 15 and time.minute == 30 and remtime == "28/04/2021":
            if not msg_sent:
                await channel.send('Its Time')
                msg_sent = True
        else:
            msg_sent = False

    await asyncio.sleep(1)
    
client.run('Your Discord Bot Token')

希望它有效。

相关问题