我不认为这是预期的行为(为什么voice_channel.members
会存在?(。
我的代码(没有什么特别的(:
class MyCog(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
@commands.Cog.listener()
async def on_ready(self):
self.guild = self.bot.get_guild(GUILD_ID)
for m in self.guild.members:
print(m.name)
在discord.py(1.5.x(的新版本中,有一些关于Intents
的更新。意图就像权限一样,你必须定义它才能获得频道、成员和一些事件等。你必须在定义client = discord.Bot(prefix='')
之前定义它。
import discord
intents = discord.Intents().all()
client = discord.Bot(prefix='', intents=intents)
如果你想获得更多关于Intents的信息,你可以看看API参考资料。