【发布时间】: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