【问题标题】:How we can we send a message in discord.py at a particular date and time我们如何在特定日期和时间在 discord.py 中发送消息
【发布时间】:2021-04-29 02:40:07
【问题描述】:

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

我希望我的机器人在该日期和时间(即 28/04/2021 和下午 3:30)发送消息。

请帮帮我。

【问题讨论】:

标签: discord.py


【解决方案1】:

我找到了类似的答案。

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

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

谢谢! :D

【讨论】:

  • 我之前访问过那个。但我没有使用 discord.ext
  • 你能分享你的版本吗
【解决方案2】:

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

这样做:

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')

希望它有效。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-25
    • 2018-06-25
    • 2020-10-15
    • 2020-10-20
    • 2019-05-18
    • 2019-12-28
    相关资源
    最近更新 更多