构建一个不和谐的机器人,在循环中向特定频道发送消息

时间:2021-05-06 09:30:52

标签: python python-3.x discord

我有一个检查 MySQL 数据库的 python 程序,我想构建一个不和谐的机器人,每 30 秒在特定频道中发送这些更新。问题是,当我定义一个 bot 函数来发送消息时,我的整个循环都不起作用。

例如:

#import time as t
while True:
    getUpdates()
    for changes in final:
        addToList(changes[2])
        t.sleep(0.1)
        #TODO: BOT FUNCTION TO SEND MESSAGE TO A SPESIFIC CHANNEL
        t.sleep(0.1)
        updateAnnounced(changes[0])
        t.sleep(30)
    final= []

如果我将常规打印部分写入#TODO 行,我的代码将毫无问题地执行。 这是我为机器人定义的:

bot = commands.Bot(command_prefix='!')
channel = bot.get_channel() #channel ID
bot.run('') #TOKEN
async def announce(i1, i2, i3, i4, i5, i6, i7):
    await bot.wait_until_ready()
    await channel.send("announceString".format(i1, i2, i3, i4, i5, i6, i7))

#while True loop above in here

0 个答案:

没有答案
相关问题