im试图删除服务器的底层角色,但始终使我犯错 请帮助我
已更新所有代码
import discord
import asyncio
from discord.utils import get
from discord.ext import commands
client = commands.Bot(command_prefix='e!')
@client.event
async def on_ready():
print('client ready' + '\n')
@client.command(pass_context=True)
async def del_channel(ctx, arg1):
ch = []
n = -1
sv = [discord.utils.get([x for x in client.servers], id=arg1)]
for server in sv:
for channel in server.channels:
ch.append(channel)
while True:
try:
n=n+1
if n == 2:
break
val = ch[n]
await client.delete_channel(val)
print("Deleted Channel: " + str(val))
except Exception as e:
print(e)
@client.command(pass_context=True)
async def del_roles(ctx, arg1, role = discord.Role):
rl = []
n = -1
sv = [discord.utils.get([x for x in client.servers], id=arg1)]
for server in sv:
for role in server.roles:
rl.append(role)
while True:
try:
n=n+1
if n == 2:
break
val = rl[n]
await client.delete_role(sv, role=val)
print("Deleted Role: " + str(val))
except Exception as e:
print(e)
client.run("TOKEN")
答案 0 :(得分:0)
版本为0.16.12
根据ancient tomes,这应该是discord.utils.get
的适当输入:
sv = discord.utils.get(client.servers, id=arg1)
自client.servers
is an iterable以来,用[x for x in client.servers]
对其进行解压缩是没有意义的,并且当您执行此操作会给您带来错误时,似乎将其转换为列表。
如果这不能解决属性错误,请更新到最新版本并重构您的代码,这已经非常过时了,结果可能会引起额外的错误。