【问题标题】:Discord.py - How to make a "flirt command" actually work?Discord.py - 如何使“调情命令”真正起作用?
【发布时间】:2020-04-29 01:17:43
【问题描述】:

该命令有效,但当您与自己调情时,它​​不会显示正确的消息。它只会显示您与其他人调情时发送的消息。

@client.command()
async def flirt(ctx, *, user):
    flirts = ["I wish I was your mirror, so that I could look at you every morning.",
    "When I need a pick me up, I just think of your laugh and it makes me smile.",
    "Sweet dreams… I hope I’m in them.",
    "If I had a candy bar for every time I thought of you, I would be fat.",
    "My heart skips a beat every time I think of you. Or maybe it’s more of a somersault.",
    "For some reason every love song makes me think of you…",
    "It’s said that nothing lasts forever. Will you be my nothing?",
    "I’m lucky because I have plans for today, for tomorrow, for the week, and for my whole life—to make you happy.",
    " I don’t think about very many things, and I don’t think for very long, but when I do think, it invariably tends to be about you.",
    "It’s not my fault that I fell for you, you tripped me!",
    "I guess your parents are bakers, because they made you such a cutie pie!",
    "You might fall from a mountain, or you might fall from a tree, but the perfect way for you to fall, is to fall in love with me."]

    if user != ctx.message.author:
        await ctx.send(str(user) + ", " + str(ctx.message.author.mention) + " flirted with you! They said: \"" + random.choice(flirts) + "\"")
    elif user == ctx.message.author:
        await ctx.send(str(ctx.message.author.mention) + ", I flirted with you! I said: \"" + random.choice(flirts) + "\"")

【问题讨论】:

  • user 是一个字符串,而ctx.message.author 是一个User 对象。您希望输入的是该对象的哪些属性?
  • 我希望当你这样做的时候!flirt @yourself,它会发送```await ctx.send(str(ctx.message.author.mention) + ",我和你调情了!我说: \"" + random.choice(flirts) + "\"") ``` 但是它发送 ``` await ctx.send(str(user) + ", " + str(ctx.message.author.mention) + " 和你调情!他们说:\"" + random.choice(flirts) + "\"") ``

标签: discord.py


【解决方案1】:

您可以使用转换器从命令调用中获取User 对象:

@client.command()
async def flirt(ctx, *, user: discord.User):
    if user != ctx.message.author:
        await ctx.send(f'{user.mention}, {ctx.message.author.mention} flirted with you! They said: "{random.choice(flirts)}"')
    elif user == ctx.message.author:
        await ctx.send(f'{ctx.message.author.mention}, I flirted with you! I said: "{random.choice(flirts)}"')

【讨论】:

  • 有效!太棒了! :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-25
  • 2020-08-16
  • 2019-07-23
  • 1970-01-01
  • 2021-08-11
  • 2021-01-02
相关资源
最近更新 更多