Python (discord.py)和#x130;要为discord服务器进行点名吗

Python (discord.py)和#x130;要为discord服务器进行点名吗,python,discord.py,Python,Discord.py,我想做一个不和谐机器人。这就是我想要的:当我说“!yoklama 11.10.2020.txt'(或其他)bot向我发送了我所在语音频道的参与者列表。[不是1个频道(我所在的频道)],但我不知道该怎么办。 然后我做了一些研究,我发现我的请求也有类似的地方。 但它们没有正常工作。 这是我找到的代码: import discord from discord.ext.commands import Bot from discord.ext import commands client = comma

我想做一个不和谐机器人。这就是我想要的:当我说“!yoklama 11.10.2020.txt'(或其他)bot向我发送了我所在语音频道的参与者列表。[不是1个频道(我所在的频道)],但我不知道该怎么办。 然后我做了一些研究,我发现我的请求也有类似的地方。 但它们没有正常工作。 这是我找到的代码:

import discord
from discord.ext.commands import Bot
from discord.ext import commands

client = commands.Bot(command_prefix='!')

@client.command()
async def attendance(ctx, filename):
    channel = client.get_channel(755129236397752441) # Replace with voice channel ID

    with open(filename, 'w') as file:
        for member in channel.members:
            file.write(member.name + '\n')


client.run('mytoken')
这些代码正在工作(当我运行时,它们不会给我错误),但当我说!注意力测试.txt 我的python shell对我说:

Ignoring exception in command attendance:
Traceback (most recent call last):
  File "C:\Users\Yunus Emre KISA\AppData\Local\Programs\Python\Python38-32\lib\site- 
packages\discord\ext\commands\core.py", line 85, in wrapped
    ret = await coro(args, **kwargs)
  File "C:\bot2\bot2.py", line 10, in attendance
    for member in channel.members:
AttributeError: 'NoneType' object has no attribute 'members'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\Yunus Emre KISA\AppData\Local\Programs\Python\Python38-32\lib\site- 
packages\discord\ext\commands\bot.py", line 903, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\Yunus Emre KISA\AppData\Local\Programs\Python\Python38-32\lib\site- 
packages\discord\ext\commands\core.py", line 859, in invoke
    await injected(ctx.args, **ctx.kwargs)
  File "C:\Users\Yunus Emre KISA\AppData\Local\Programs\Python\Python38-32\lib\site- 
packages\discord\ext\commands\core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 
'NoneType' object has no attribute 'members
你们看,伙计们,我什么都不懂,请帮帮我。 我发现了这些问题,但它对我不起作用:

我不必在命令中传递文件,只需编写函数:

with open("file.txt", "w") as f:

谢谢你的回答,但当我对机器人说!测试它不会给出任何反应(python shell也是如此)这是我的代码:从discord导入discord.ext.commands从discord导入Bot.ext导入commands client=commands.Bot(command_prefix='!')@client.command()异步定义测试(ctx):guild=ctx.guild channel=discord.utils.get(guild.voice_channels,name='a'))对于channel.members中的成员:打印('test'),并将open(“file.txt”,“w”)作为f:对于channel.members:file.write(member.name+'\n')client.run('mytoken')中的成员
with open("file.txt", "w") as f: