我正在尝试制作一个每 15 分钟发送一条随机消息的机器人。机器人加载没有问题,但没有发送消息,我是否遗漏了什么?import discordimport asyncioimport randomfrom discord.ext import commands, tasksclient = discord.Client()token = 'xxx'@tasks.loop(seconds=5)async def background_loop(): await client.wait_until_ready() while not client.is_closed: channel = client.get_channel(xxx) messages = ["Hello!", "How are you doing?", "Howdy!"] await channel.send(random.choice(messages))background_loop.start()@client.eventasync def on_ready(): print('Logged in as') print(client.user.name) print(client.user.id) print('------')client.run(token)
1 回答
![?](http://img1.sycdn.imooc.com/545868190001d52602200220-100-100.jpg)
Qyouu
TA贡献1786条经验 获得超11个赞
如果您尝试使用tasks
,那么您的使用方式就有点错误了。这是有关如何使用的文档tasks
。另外,没有什么像client.send_message
. 你可以这样做channel.send(message)
。
@tasks.loop(minutes=15.0)
async def background_loop():
await client.wait_until_ready()
while not client.is_closed:
channel = client.get_channel(id)
messages = ["Hello!", "How are you doing?", "Howdy!"]
await channel.send(random.choice(messages))
background_loop.start()
添加回答
举报
0/150
提交
取消