Python Discord.py Bot不会在启动Bot之前注册对消息的反应

2024-05-08 02:21:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在为服务器编写一个discord bot,我想在有人对消息做出反应时检测它。当机器人处于活动状态时,它可以完美地处理发送的所有消息。但是,在bot联机之前发送的任何消息都不会被拾取。几乎就好像机器人根本没有监视它们一样

以下是我正在使用的代码:

@client.event async def on_reaction_add(reaction, user):
#ensures the message is not from itself and it's in the right channel
if reaction.message.author == client.user or reaction.message.channel.name != 'basement-bets':
    return

#calls the appropriate function based on the emoji sent by the mod
if reaction.emoji == '👍':
    outPut = betting.bet_won(reaction.message.id)
    await client.get_channel(channel).send('{0.author.mention}, '.format(reaction.message) + outPut)
    print(outPut)

我已经搜索了API,我很难理解为什么会这样,或者我如何扩大机器人程序视图的范围,这应该是问题所在

非常感谢大家的帮助

编辑:澄清一下,我的意思是,一旦我打开它并且它在线,它就不会监视在它打开之前发送的消息。甚至在上网之后


Tags: the服务器client消息messageoutputifon
1条回答
网友
1楼 · 发布于 2024-05-08 02:21:15

无法让Bot在脱机时工作。然而,有解决办法

也许你可以试着把你的机器人放在像Heroku这样的东西上,如果你使用免费计划,它将在一个月的3/4时间内在线。(如果你有困难,考虑看YouTube教程)

但是,如果你想让它全天候在线,那么你可能需要付费

相关问题 更多 >