【发布时间】:2021-09-12 06:17:36
【问题描述】:
当我尝试使用以下代码运行命令$getUserId @user 时,它按预期工作,但在尝试传递参数时发送$getUserId 123 之类的内容时会出错。
我想要一个不会出错的机器人。
import discord
client = commands.Bot(command_prefix = "$")
@client.command()
async def getUserId(ctx, *user: discord.User):
if not arg:
userId = ctx.author.id
else:
userId = arg.id
await ctx.send(userId)
如果给出$getUserId 命令,我将如何处理:将提到的用户作为参数并处理所有异常?
或
有没有更简单的方法从提及中获取用户 ID?必须有一个简单的方法来做到这一点,对吧? 无论如何,非常感谢所有帮助。
【问题讨论】:
标签: python discord discord.py