python - Discord.py 收集表情符号反应并利用它们制作功能
问题描述
每当用户对检查表情符号做出反应或他们对 x 做出反应时,我都会尝试创建一个函数。所以基本上我检查用户是否有电话,如果用户有电话,那么你可以打电话给他们。机器人在 dms 中发送一条消息,并用检查和斧头做出反应,如果您单击检查我想要一个功能发生,我该怎么做?
@commands.command()
@commands.cooldown(1,120,commands.BucketType.user)
async def call(self, ctx, member : discord.Member):
phone = False
users = await bank_data()
user = ctx.author
client = discord.Client
try:
bag=users[str(user.id)]["bag"]
except:
bag=[]
for item in bag:
name = item["item"]
if name == "phone":
phone = True
if phone == False:
await ctx.reply("You must buy a phone to call someone idiot.")
if phone == True:
try:
targetBag = users[str(target.id)]["bag"]
except:
targetBag=[]
targetPhone = False
if target:
for item in targetBag:
name = item["item"]
if name =="phone":
targetPhone = True
if targetPhone == False:
await ctx.reply("Attempted user to call does not have a phone.")
if targetPhone == True:
channel = await target.create_dm()
emojis=['✅', '❌']
confirmEmoji = '✅'
message=await channel.send(f"{ctx.author} is calling you. Do you want to answer?")
for emoji in emojis:
await message.add_reaction(emoji)
解决方案
您可以在wait_for()
这种情况下使用 。创建一个响应变量,以便您可以检查并使用响应来接听电话或拒绝接听电话。您可以在此处阅读更多相关信息 -
https://discordpy.readthedocs.io/en/stable/api.html#discord.Client.wait_for
wait_for()
在您的情况下,您可以传递不同类型的事件reaction_add
希望这有帮助:D
推荐阅读
- java - 在 RewriteRule 激活时跟踪 AccessLog
- docker - Docker pull - 从 Gitlab CI 构建并推送到 Heroku
- html - 为什么输入行为会这样工作?
- xamarin - Visual Studio Mac 2017 在构建时挂起
- date - 如何在 ArangoDB 中循环日期范围
- vb.net - 自动实现的属性会导致空引用,而完整的写入属性不会
- asp.net - 如何在具有相同主机和端口的 IIS 上添加多个 asp.net 应用程序/
- python - Python Pandas:当 df.columns = df.columns.droplevel() 时浮点值分解
- javascript - JS判断网页是否被手机打开
- reactjs - React、Redux、Api、Postman 编程中的重复声明“Main”