메시지에 언급 된 모든 사람이 봇의 응답에 반응 할 때 원래 메시지 작성자를 언급하는 봇에 대한 명령을 만들려고합니다.
그게 내가 시도한 것입니다
if msg.content.startswith('/iniciar'):
async with msg.channel.typing():
mentions = ""
for mention in msg.mentions:
mentions = mentions + " " + mention.mention
bot_msg: discord.Message = await msg.channel.send(mentions + ' confirmem presença reagindo abaixo.')
await bot_msg.add_reaction('✅')
for mention in msg.mentions:
def check(reaction, user):
return user == mention and str(reaction.emoji) == '✅'
try:
reaction, user = await client.wait_for('reaction_add', check=check)
finally:
reactionusers: list = await reaction.users().flatten()
reactionusers.remove(reactionusers[0])
print(reactionusers)
print(msg.mentions)
if reactionusers == msg.mentions:
await msg.channel.send(msg.author.mention)
else:
return
우선,이 현재 구현에서 몇 가지 사항을 고려해야합니다. 우선, 봇이 어딘가에 보길 원하는 메시지 ID를 저장하고 싶을 것입니다. 이것이 SQL인지 Shelve인지 여부
이를 위해 /iniciar
함수가 호출되면 봇이 확인할 수있는 원하는 장기 저장 방법에 메시지 ID를 저장합니다.
그런 다음 현재 주어진 코드에서 볼 수없는이 코드 블록을 활성화하는 방법을 고려하고 싶을 것입니다. 귀하의 목적을 위해 https://discordpy.readthedocs.io/en/latest/api.html#discord.on_reaction_add에on_reaction_add
문서가있는 것을 사용 하는 것이 좋습니다 .
사용 Reaction.message
메시지 개체를 잡아하고 (당신이하고있는 방식과 유사) 목록에 메시지에서 언급 한 사람에 대한 관련 정보를 읽을 수 있습니다.
사용자가 메시지에 반응하고 on_reaction_add
호출 될 때 :
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다