简体   繁体   English

Discord 机器人(python)每分钟自行编辑自己的消息

[英]Discord bot (python) edit own message itself every minute

import os
import discord
import requests
import time
import datetime

class MyClient(discord.Client):
    async def on_ready(self):
        await client.change_presence(activity=discord.Activity(type=0, name='HIDDENSTATUS'))
        print('Logged on as {0}!'.format(self.user))
        
    async def on_message(self, message):
        msglower = message.content.lower()
        channelStatusSV = client.get_channel(HIDDENCHANNELID)  
        if msglower == '!refresh':
            standard = formated_info('HIDDENIP', '36963', 'ok')         
            messageStandard = await channelStatusSV.fetch_message(HIDDENMESSAGEID)
            await messageStandard.edit(content=standard)   

client = MyClient()
client.run('HIDDENTOKEN')

This is the full script (with some hidden info like IP, URL, etc).这是完整的脚本(带有一些隐藏信息,如 IP、URL 等)。

It fetches my game server info into an embedded bot message.它将我的游戏服务器信息提取到嵌入式机器人消息中。 Currently, it fetches info on demand.目前,它按需获取信息。

How can I change it to automatically fetch every minute?如何将其更改为每分钟自动获取一次?

Assuming that you're using discord.py ;假设您使用的是discord.py you can usetasks , Have it loop on the interval you want, query the server.你可以使用tasks ,让它在你想要的时间间隔内循环,查询服务器。 and update the message.并更新消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM