为了账号安全,请及时绑定邮箱和手机立即绑定

每 15 分钟发送一条关于 Discord 的消息

每 15 分钟发送一条关于 Discord 的消息

慕妹3242003 2023-10-25 10:44:54
我正在尝试制作一个每 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 回答

?
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()


查看完整回答
反对 回复 2023-10-25
  • 1 回答
  • 0 关注
  • 48 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信