邀请命令进入不和.py(按ID邀请用户到服务器)

2024-10-01 17:21:26 发布

您现在位置:Python中文网/ 问答频道 /正文

正如标题所示,我想在我的bot中添加一个命令,它将向服务器发出邀请。使用永久性的静态链接不是一个选项,因为我希望命令可以跨不同的服务器使用。在

到目前为止,我得到的是:

@BSL.command(pass_context = True)
async def invite(ctx, userToInvite):
        inviteLinq = await BSL.create_invite(destination = ctx.message.channel, xkcd = True, max_uses = 1)
        await BSL.send_message(userToInvite, inviteLinq)

但是,我得到一个错误InvalidArgument: Destination must be Channel, PrivateChannel, User, or Object. Received str。我知道这是因为不和谐中的消息被保存为字符串。在

有没有一种方法可以让你指定一个用户的ID,让他们在DMs中收到invite链接?在


Tags: 命令服务器true标题message链接bot选项
1条回答
网友
1楼 · 发布于 2024-10-01 17:21:26

您的userToInvite是一个字符串,但它应该是一个User对象。您应该使用^{}从服务器获取Member对象。有点像

@BSL.command(pass_context = True)
async def invite(ctx, userToInvite):
        inviteLinq = await BSL.create_invite(destination = ctx.message.channel, xkcd = True, max_uses = 1)
        target_member = await ctx.message.server.get_member_named(userToInvite)
        await BSL.send_message(target_member, inviteLinq)

编辑:

如果使用用户的id邀请用户访问此服务器,则应尝试

^{pr2}$

相关问题 更多 >

    热门问题