如何在discord.py循环中发送消息?

2024-09-27 00:23:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我想让我的机器人能够以自定义循环时间在循环中发送消息 例如!提醒60秒将使机器人在60秒内发出提醒 例如!提醒23秒将使机器人在23秒内发出提醒

我现在有这个,但不起作用。 如果您能提供一个很好的例子,我们将不胜感激。谢谢

@tasks.loop(seconds=timeP)
async def Reminder():

timeP = 5
channel = client.get_channel(717689495620681731)
await client.change_presence(activity=discord.Game('online'))
print('test')
await channel.send('<@&717696163574186026> here')

Tags: clientloop消息getasyncdef时间channel
1条回答
网友
1楼 · 发布于 2024-09-27 00:23:08

您可以使用discord.py中的task装饰器:

import discord
from discord.ext import task

@tasks.loop(seconds=x) #you can also have minutes=x or hours=x
    async def printer(self):
        channel = client.get_channel(717689495620681731)
        await client.change_presence(activity=discord.Game('online'))
        print('test')
        await channel.send('<@&717696163574186026> here')

相关问题 更多 >

    热门问题