使用 discord.py 检查频道中用户的最简单方法

时间:2021-01-10 22:04:45

标签: python-3.x discord discord.py

我正在制作一个简单的机器人,我想要它做的就是等待我输入一个带有参数(一个 vc)的命令,例如当我输入 C:\Windows\system32>python -m pip install -U setuptools pip Requirement already satisfied: setuptools in c:\users\c\appdata\local\programs\python\python38-32\lib\site-packages (51.1.2) Requirement already satisfied: pip in c:\users\c\appdata\local\programs\python\python38-32\lib\site-packages (20.3.3) C:\Windows\system32>pip install cupy-cuda111 ERROR: Could not find a version that satisfies the requirement cupy-cuda111 ERROR: No matching distribution found for cupy-cuda111 时,机器人将返回一个列表该频道中的成员。因此,如果 Bob 和 Jeff 在一般情况下,机器人将返回 !channel general 任何简单的方法来做到这一点?

更新:

member_list = ['Bob', 'Jeff']

这是我上面的代码,当我运行 bot 时,当我输入 import discord import os from discord.ext import commands client = discord.Client() bot = commands.Bot(command_prefix='$') @client.event async def on_ready(): print('We have logged in as {0.user}'.format(client)) @bot.command() async def members(ctx, channel: discord.VoiceChannel): member_list = [i.name for i in channel.members] print(member_list) await ctx.send(member_list) # or return member_list whatever you want client.run(os.getenv('TOKEN')) 时它什么也不做,有人知道我做错了什么吗?

1 个答案:

答案 0 :(得分:0)

使用VoiceChannel.members

@bot.command()
async def members(ctx, channel: discord.VoiceChannel):
    member_list = [i.name for i in channel.members]
    await ctx.send(member_list) # or return member_list whatever you want
相关问题