繁体   English   中英

discord.py massban 命令不起作用?

[英]discord.py the massban command doesn't work?

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

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)```

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

确保在Discord 开发人员门户中为您的应用程序打开所有必要的功能。

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

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

您还可以阅读文档以获取更多信息。

您的完整代码将是:

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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM