【问题标题】:discord.py the massban command doesn't work?discord.py massban 命令不起作用?
【发布时间】:2021-04-16 18:03:21
【问题描述】:

所以我制作了这个简单的脚本来在测试服务器上对其进行测试,代码没有给出错误/日志但它不起作用,确切地说是禁止任何人。有任何想法吗? (仅用于测试和教育目的。)

from discord.ext import commands
import random
import colorama
from discord import Permissions
from colorama import Fore, Style
import asyncio

token = "token"


client = commands.Bot(command_prefix="y!")


@client.event
async def on_ready():
  print('''
  
  READY
  ''')
  await client.change_presence(activity=discord.Game(name="test"))


@client.command()
async def bonk(ctx):
  for user in ctx.guild.members:
    try:
      await user.ban()
    except:
        pass

client.run(token, bot=True)```

【问题讨论】:

  • 它没有给出错误,因为您使用 try/except 块抑制错误
  • 那么有没有办法解决这个问题并让它工作..?
  • 你导入Intents了吗?
  • 不,还没有导入 Intents
  • 您可以通过将except 替换为except Exception as e: 并打印str(e) 来检查异常,这将提供错误消息

标签: python discord.py


【解决方案1】:

看起来 Intent 丢失了,因为您说您没有导入它们。没有 Intents,你无法捕获公会中的所有成员。

确保为您的应用打开Discord Developer Portal 中所有必要的选项。

要将它们实现到您的代码中,您可以使用以下代码:

intents = discord.Intents.all() # Imports all the Intents
client = commands.Bot(command_prefix="YourPrefix", intents=intents)

您也可以阅读docs 了解更多信息。

您的完整代码是:

Imports shortened

token = "token"

intents = discord.Intents.all()
client = commands.Bot(command_prefix="y!", intents=intents)


@client.event
async def on_ready():
  print('''READY''')
  await client.change_presence(activity=discord.Game(name="test"))


@client.command()
async def bonk(ctx):
  for user in ctx.guild.members:
    try:
      await user.ban()
    except:
        pass

client.run(token, bot=True)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-16
    • 2019-07-23
    • 1970-01-01
    • 2021-07-27
    • 2022-01-24
    • 2021-03-24
    • 2022-01-19
    • 2021-08-28
    相关资源
    最近更新 更多