【问题标题】: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】:
有两种方式:
- 您将其设置为 None 并签入命令。
- 直接在参数中设置频道
第一种方式:
@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)