【问题标题】:How to send message in loop of discord.py?如何在 discord.py 循环中发送消息?
【发布时间】:2020-10-01 01:45:06
【问题描述】:

我想让我的机器人能够使用自定义循环时间循环发送消息 例如。 !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')

【问题讨论】:

标签: python loops discord discord.py-rewrite


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-04
    • 2019-04-14
    • 2020-10-15
    • 2021-07-08
    • 2021-10-15
    • 1970-01-01
    • 2021-02-24
    • 2021-03-11
    相关资源
    最近更新 更多