【发布时间】:2018-10-28 08:53:57
【问题描述】:
discord 上的服务器所有者要求我为他的机器人添加自定义货币系统(机器人仅在此服务器上)。为了鼓励活动,我们没有使用样片系统,而是我的想法是每 7 分钟弹出一条带有图像的消息,用户必须向图像添加“反应”。为了方便和控制输入,我想为我的图像添加一个反应,这样用户只需点击反应,它就会添加数量。
排除了所有这些上下文,这是作为后台任务的问题。我不知道如何将上下文传递给反应!
async def my_background_task():
await bot.wait_until_ready()
counter = 0
channel = discord.Object(id='446782521070321664')
while not bot.is_closed:
counter += 1
with open('vbuck.png', 'rb') as f:
await bot.send_file(channel, f) #sends a png of a vbuck
await bot.add_reaction(discord.message,'<:vbuck:441740047897591809>') #This is the Reaction part
await asyncio.sleep(420) # task runs every 7 min seconds
bot.loop.create_task(my_background_task())
如果您能给我一些很棒的建议,并且如果您觉得代码和解释更加慷慨,我将不胜感激,我正在从这个项目中学习 python。
【问题讨论】:
标签: python python-3.x discord discord.py