如何让我的 discord.py 机器人提及我的消息中提到的某人?

Posted

技术标签:

【中文标题】如何让我的 discord.py 机器人提及我的消息中提到的某人?【英文标题】:How can I make my discord.py bot mentions someone mentioned in my message? 【发布时间】:2021-01-27 08:12:12 【问题描述】:

所以我知道堆栈溢出有一个类似的问题,但它是针对 discord.js 的,我使用 discord.py 所以有人可以告诉我(这也是我关于堆栈溢出的第一个问题)

【问题讨论】:

请完善您的问题并提供您尝试过的示例。有关提问的帮助,请参阅here。否则我很乐意提供帮助,只是有点困惑 【参考方案1】:

好的,所以上面的几乎是正确的。 解决办法是:

@client.command()
async def something(ctx, target:discord.Member = None):
    if target == None:
        await ctx.send("You didn't mention anyone!")
    
    else:
        await ctx.send(target.mention)
#whatever other code

所以它是 target:discord.Member = None 而不是 target:discord.Member == None 并且 async def thingy of course :)

【讨论】:

【参考方案2】:

(这也是我第一次回复!)

这么说

import discord
from discord.ext import commands #or command I can't remember)

#setup setting(on_ready.. etc)

@client.command(ctx, target:discord.Member == None) #CTX represents your command, target means your mentioned member

if target == None:
    await ctx.send("You didn't mention anyone!")
else:
    await ctx.send(target.mention)

#client run token

【讨论】:

它是target:discord.Memeber = None 我怎么会错过这个?‍♂️?‍♂️ 没关系 NastyCore 我们都会犯一些小错误

以上是关于如何让我的 discord.py 机器人提及我的消息中提到的某人?的主要内容,如果未能解决你的问题,请参考以下文章