簡體   English   中英

如何在 discord.py 的循環中發送消息?

[英]How to send message in loop of discord.py?

我想讓我的機器人能夠使用自定義循環時間循環發送消息,例如。 .remind 60s 會讓機器人在 60 秒內說提醒,例如。 !remind 23s 會讓機器人在 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')

您可以使用 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')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM