这就是我到目前为止所拥有的......确实适用于我想要的延迟秒数,但是如何添加时间模块或时间表模块以使其工作......
以防万一我希望机器人每 24 小时发送一次消息
import discord
import asyncio
from discord.ext import commands
import schedule
import time
TOKEN = 'xxxxx'
client = commands.Bot(command_prefix = '.')
channel_id = '515994xxxxx5036697'
@client.event
async def on_ready():
print('Bot Online.')
async def alarm_message():
await client.wait_until_ready()
while not client.is_closed:
channel = client.get_channel(channel_id)
messages = ('test')
await client.send_message(channel, messages)
await asyncio.sleep(5) #runs every 5 seconds
client.loop.create_task(alarm_message())
client.run(TOKEN)
您可以使用以下方法执行此操作discord.ext.tasks https://discordpy.readthedocs.io/en/stable/ext/tasks/index.html.
import discord
import asyncio
from discord.ext import commands
from discord.ext import tasks
import time
TOKEN = 'xxxxx'
client = commands.Bot(command_prefix = '.')
channel_id = '515994xxxxx5036697'
@client.event
async def on_ready():
print('Bot Online.')
@tasks.loop(days=1)
async def alarm_message():
await client.wait_until_ready()
channel = client.get_channel(channel_id)
message = 'test'
await channel.send(message)
alarm_message.start()
client.run(TOKEN)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)