我正在尝试对始终在频道中的消息进行反应并删除反应。在下面的代码中,我试图通过ID来获取消息,然后对其进行响应,然后在循环中消除响应。我收到以下错误:
Task exception was never retrieved
future: <Task finished coro=<react() done, defined at c:/Users/test/Desktop/test bot/test.py:161> exception=InvalidArgument('message argument must be a Message',)>
Traceback (most recent call last):
File "c:/Users/test/Desktop/test bot/test.py", line 167, in react
await client.add_reaction(msg, emoji1)
File "C:\Users\test\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\client.py", line 949, in add_reaction
raise InvalidArgument('message argument must be a Message')
discord.errors.InvalidArgument: message argument must be a Message
Test Bot Online.
Future exception was never retrieved
future: <Future finished exception=ServerDisconnectedError()>
aiohttp.errors.ServerDisconnectedError
client = discord.Client()
async def react():
await client.wait_until_ready()
channel = client.get_channel("479919577279758111")
while not client.is_closed:
msg = get(client.get_message(channel,'505306270891507712'))
emoji1 = get(client.get_all_emojis(), name='gsmile')
await client.add_reaction(msg, emoji1)
await client.remove_reaction(msg, emoji1)
await asyncio.sleep(5)
@client.event
client.loop.create_task(react())
答案 0 :(得分:1)
msg = get(client.get_message(channel,'505306270891507712'))
可能是您的问题所在。
msg = client.get_message(channel,'505306270891507712')
足以获取Message
对象。您还添加了一个反应,然后立即将其删除。我不确定这是否是您想要的。
您还需要将Member
对象传递给remove_reaction
:
await client.remove_reaction(msg, emoji1, channel.server.me)
答案 1 :(得分:0)
我相信您不能使用名称添加反应,您必须输入代码或实际的表情符号。您也不需要任务创建上方的@client.event
。