我制作了一个机器人,该机器人以60秒的间隔将随机消息发送到所有服务器和通道,但是它似乎不起作用。这是我的代码:
import discord
import asyncio
client = discord.Client()
async def my_background_task():
await client.wait_until_ready()
while not client.is_closed:
for server in client.servers:
for channel in server.channels:
await client.send_message(channel, "Some message")
await asyncio.sleep(60) # task runs every 60 seconds
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
client.loop.create_task(my_background_task())
client.run('<my token>')
以上内容不会引发任何错误。我要去哪里错了?