【发布时间】:2019-10-04 01:24:57
【问题描述】:
我需要一个 kick all 命令以有趣的方式终止服务器
@bot.command(pass_context=True)
async def kick_all(ctx):
while True:
for server_member in ctx.message.server.members:
try:
channel = bot.get_channel('540612578401976330')
await bot.kick(server_member)
await bot.send_message(channel, "someone got kicked")
except discord.Forbidden:
pass
输出:
Ignoring exception in command kick_all
Traceback (most recent call last):
File "C:\Users\adamk\PycharmProjects\bot\venv\lib\site-packages\discord\ext\commands\core.py", line 50, in wrapped
ret = yield from coro(*args, **kwargs)
File "C:/Users/adamk/PycharmProjects/bot/Server_KillSwitch.py", line 18, in kick_all
for server_member in ctx.message.server.members:
RuntimeError: dictionary changed size during iteration
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\adamk\PycharmProjects\bot\venv\lib\site-packages\discord\ext\commands\bot.py", line 846, in process_commands
yield from command.invoke(ctx)
File "C:\Users\adamk\PycharmProjects\bot\venv\lib\site-packages\discord\ext\commands\core.py", line 374, in invoke
yield from injected(*ctx.args, **ctx.kwargs)
File "C:\Users\adamk\PycharmProjects\bot\venv\lib\site-packages\discord\ext\commands\core.py", line 54, in wrapped
raise CommandInvokeError(e) from e
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: RuntimeError: dictionary changed size during iteration
【问题讨论】:
标签: python python-3.x discord discord.py