【问题标题】:Discord.py check define message.contentDiscord.py 检查定义 message.content
【发布时间】:2021-07-30 17:32:16
【问题描述】:

我想检查我何时使用命令,我发送了哪个对象,例如用户/成员、频道、角色

@foo.command()
async def define(ctx, arg) #the arg as id, mention or name
   if arg == discord.Role:
     await ctx.send("its a role")
   elif == discord.Channel:
     await ctx.send("its an channel")
    # more checks

【问题讨论】:

    标签: python python-3.x discord.py


    【解决方案1】:

    这是可以做到的。看看:

    import typing #module you need
    ...
    arg: typing.Union[discord.Member, discord.User, discord.Role, discord.Channel, int] = None) #arg itself
        ...
        if arg is None: #checking if arg is none
            ...
        elif isinstance(arg, int): #chechking if arg is int
            try:
                arg = ctx.guild.get_channel(channel) or (await ctx.guild.fetch_channel(channel)) #checking if bot can get/fetch channel by its id
            except Exception:
                ...
                try:
                ... #if bot didn't manage to get/fetch channel, then you should try with roles, users etc
            ...
        if isinstance(error, commands.BadUnionArgument): #error handler
            ...
    

    :D

    【讨论】:

    • 谢谢,我如何在 bot.wait_for 函数中使用它?
    • 什么意思?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-12-10
    • 1970-01-01
    • 2021-01-13
    • 1970-01-01
    • 1970-01-01
    • 2021-11-24
    • 1970-01-01
    相关资源
    最近更新 更多