1

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

4

2 回答 2

0

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

所以让我们说

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

于 2020-10-13T02:34:22.767 回答
0

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

@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 == Noneasync def thingy ofcourse :)

于 2020-10-13T05:35:35.487 回答