每当用户对勾选表情符号做出反应或对x做出反应时,我都会尝试创建一个函数。所以基本上,我会检查用户是否有电话,如果用户有电话,你可以打电话给他们。机器人在dms中发送一条消息,并用一个check和一个x做出反应,如果你点击check,我想让一个函数发生,我该怎么做?
@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