【问题标题】:Discord.py default value if not given如果没有给出 Discord.py 默认值
【发布时间】:2020-12-04 12:59:58
【问题描述】:
@bot.command(pass_context=True)
async def move(ctx, member: discord.Member, channel: discord.VoiceChannel):
    await member.edit(voice_channel=channel)

我正在尝试制作 如果 channel 未设置,则将其设置为 687744572042117243 有什么想法吗?

【问题讨论】:

    标签: python discord bots discord.py


    【解决方案1】:

    有两种方式:

    1. 您将其设置为 None 并签入命令。
    2. 直接在参数中设置频道

    第一种方式:

    @bot.command()
    async def move(ctx, member: discord.Member, channel: discord.VoiceChannel=None):
        channel = channel if channel else bot.get_channel(687744572042117243)
        await member.edit(voice_channel=channel)
    

    第二种方式:

    @bot.command()
    async def move(ctx, member: discord.Member, channel: discord.VoiceChannel=bot.get_channel(687744572042117243)):
        await member.edit(voice_channel=channel)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-25
      • 2022-01-08
      • 2012-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-05
      • 2018-02-18
      相关资源
      最近更新 更多