擅长:python、mysql、java
<p>这与使用<code>Client</code>而不是<code>Bot</code>无关</p>
<p>您创建了<code>intents</code>变量,但从未使用过它。您应该将它传递到您的<code>discord.Client()</code>,而您没有这样做,因此<code>members</code>意图将始终被禁用</p>
<pre class="lang-py prettyprint-override"><code># Original question
intents = discord.Intents.default()
intents.members = True
client = discord.Client() # < You're not passing intents here! The variable is never used so intents are disabled
</code></pre>
<p>这也是为什么你的答案能解决这个问题:因为你实际上是在使用你的意图</p>
<pre class="lang-py prettyprint-override"><code># Your "fix"
client = commands.Bot(command_prefix = "!", intents = intents) # < Notice the intents
</code></pre>
<p>使用<code>discord.Client</code>或<code>commands.Bot</code>对这一点没有影响:<code>commands.Bot</code><em>没有</em>传递意图也不会做任何事情</p>
<pre class="lang-py prettyprint-override"><code># This would cause the exact same issue, because intents aren't used
client = commands.Bot(command_prefix = "!")
</code></pre>
<p>将您的意图传递到<code>Client</code>也会起作用,就像这样可以解决<code>Bot</code>的问题</p>
<pre class="lang-py prettyprint-override"><code>client = discord.Client(intents=intents)
</code></pre>