【问题标题】:How I can get channel members (Discord.py)我如何获得频道成员 (Discord.py)
【发布时间】:2021-03-31 22:05:14
【问题描述】:

我需要仅获取我频道的用户,但我还没有找到返回所需结果的函数。有一个功能可以让机器人的所有用户:get_all_members(),但她并没有完全满足我的需要。我想获得用户昵称。 帮我找到解决问题的方法。

【问题讨论】:

  • discordpy.readthedocs.io/en/latest/… 一旦你有了channel 对象,你就可以做channel.members
  • 我无法在聊天中发送用户,我收到错误:discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: can only concatenate str (not "Member") to str
  • 拥有member 对象后,您可以通过member.mention 获取提及字符串
  • 我创建一个频道变量并发送频道成员

标签: python discord discord.py


【解决方案1】:

嗯...我在不久前制作的机器人中遇到了这个问题...

假设您希望人们在您当前所在的语音频道中,这里是获取语音频道用户的代码...

def foo(ctx):
    voice_channel_list = ctx.guild.voice_channels
    for voice_channels in voice_channel_list:
        for member in voice_channels.members:

这将为您提供当前所在的语音频道ctx.author 的所有成员对象。我希望这是您正在寻找的。如果没有,请告诉我,我会更改答案(如果我知道答案)。

【讨论】:

  • 哦,好的,谢谢您的勾选。编码愉快!
【解决方案2】:

也许你可以试试

client.users

for i in range(len(client.users)):
    print(client.users[i].name)

希望对大家有帮助。

【讨论】:

    猜你喜欢
    • 2021-07-21
    • 1970-01-01
    • 2020-12-21
    • 2021-02-27
    • 2021-02-26
    • 2020-12-01
    • 2021-06-05
    • 2022-09-25
    • 2018-10-09
    相关资源
    最近更新 更多