小编mbe*_*eri的帖子

使用 Discord.py 制作一个在预定日期发送消息的机器人

我正在尝试制作一个向特定文本频道发送预定消息的机器人。例如在我生日那天说“生日快乐”,或者每天早上说“早上好”。机器人似乎不起作用,因为我的文本频道中没有任何内容。

import discord,random,asyncio,os
from datetime import datetime
from discord.ext import commands

token = '#mytokenhere'
bot=commands.Bot(command_prefix='!')

send_time='01:41' #time is in 24hr format
message_channel_id='0000000000000' #channel ID to send images to

@bot.event
async def on_ready():
    print(bot.user.name)
    print(bot.user.id)

async def time_check():
    await bot.wait_until_ready()
    message_channel=bot.get_channel(message_channel_id)
    while not bot.is_closed:
        now=datetime.strftime(datetime.now(),'%H:%M')
        if now.hour() == 1 and now.minute() == 52:
            message= 'a'
            await message_channel.send(message)
            time=90
        else:
            time=1
        await asyncio.sleep(time)

bot.loop.create_task(time_check())


bot.run('token')
Run Code Online (Sandbox Code Playgroud)

python bots timer discord discord.py

0
推荐指数
1
解决办法
1万
查看次数

标签 统计

bots ×1

discord ×1

discord.py ×1

python ×1

timer ×1