【发布时间】:2021-01-25 19:22:02
【问题描述】:
我想做一个不和谐的机器人。这就是我想要的:当我说“!yoklama 11.10.2020.txt”(或其他内容)时,机器人会向我发送我所在语音频道的参与者列表。[不是 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')
此代码正在运行(当我运行时它们不会给我错误)但是当我说 !attendence test.txt bot 什么也没说,我的 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
你们看,我什么都不懂,请帮帮我。 我发现了这些问题,但它对我不起作用: Discord Python bot creating a file of active member in a vocal channel
【问题讨论】:
标签: python discord.py