我试图做出一个在语音通道中选择多个人并提及他们的命令。
目前,我做到了,所以有人提到:
@commands.command()
async def hns(self, message):
await message.channel.send(choice(tuple(member.mention for member in message.author.voice.channel.members if not member.bot)))
await message.channel.send("You have been chosen to seek.")
我一直在尝试在命令中添加一个参数,例如arg
,但是我不确定从那里去哪里。
可能的解决方案:
我不习惯使用message参数,所以不确定,但是也许可以使用ctx
更多内容?
有任何想法吗?
使用修饰符的命令中的第一个参数始终是上下文对象,它们只是ctx
按约定调用。这意味着您的message
arg实际上是上下文对象。
另一个可能的解决方案是改组成员列表,然后选择x个成员,如下所示:
@commands.command()
async def hns(self, ctx, amount: int):
members = [m.mention for m in ctx.author.voice.channel.members if not m.bot]
random.shuffle(members) # shuffles it in place, i.e. doesn't return the list
selected = members[:amount]
await ctx.send(f"{', '.join(selected)}, you've been chosen to seek!")
该命令的用法是:
!hns 3
随机选择3个用户。这样可以避免必须使用硬编码的值,尽管您可以根据需要这样做。
参考文献:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句