如何解决Discord.py默认值如果未提供
@bot.command(pass_context=True)
async def move(ctx,member: discord.Member,channel: discord.VoiceChannel):
await member.edit(voice_channel=channel)
我试图使如果未设置频道,然后使其变为687744572042117117243 有什么想法吗?
解决方法
有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,channel: discord.VoiceChannel=bot.get_channel(687744572042117243)):
await member.edit(voice_channel=channel)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。