[英]Nuke every channel in a server discord.py
所以这以前有效,但突然不起作用。 这段代码的重点是它遍历服务器中的每个文本通道并对其进行核对(基本上重新克隆并删除旧通道,同时将重新克隆的通道保留在那里)。 但是,它现在只适用于少数频道,然后停止说:
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: NotFound: 404 Not Found (error code: 10003): Unknown Channel
现在,我是 discord.py 的新手。 因此,如果有人可以向我展示此修复代码,我将不胜感激,并附上一个小解释,以便我知道我做错了什么。我尝试通过将重新克隆的频道添加到列表中来自己修复它,并将其附加到该列表如果它看到该频道,则跳过它,但代码不起作用。 下面是我的代码,如果有人展示了它的修复代码及其工作原理,我将非常感激:
@client.command()
async def reclone(ctx):
for channel in ctx.guild.text_channels:
time.sleep(0.2)
print(f"Cloning {channel.name}")
newchannel = await channel.clone(reason="Channel has been nuked")
print(f"Cloned {channel.name}")
await channel.delete()
print(f"Nuked {channel.name}")
time.sleep(0.2)
# Editing the position here
await newchannel.edit(position=channel.position)
print(f"Repositioned {newchannel.name}")
await newchannel.send("**[Soon]** :copyright:")
print(f"Sent message to {newchannel.name}")
我已经完成了ctx.guild.text_channels
因为我只希望它删除服务器中的所有文本通道并重新克隆,仅此而已。
看起来您的代码是正确的,您只需要确保机器人具有正确的权限:尝试授予它管理员权限。
这是我使用的代码:
import discord
from discord.ext import commands
from discord.ext.commands import has_permissions
import time
intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix = ".", intents=intents)
@bot.command()
async def reclone(ctx):
for channel in ctx.guild.text_channels:
time.sleep(0.2)
print(f"Cloning {channel.name}")
newchannel = await channel.clone(reason="Channel has been nuked")
print(f"Cloned {channel.name}")
await channel.delete()
print(f"Nuked {channel.name}")
time.sleep(0.2)
# Editing the position here
await newchannel.edit(position=channel.position)
print(f"Repositioned {newchannel.name}")
await newchannel.send("**[Soon]** :copyright:")
print(f"Sent message to {newchannel.name}")
bot.run("BOT TOKEN HERE")
(我只是添加了一些东西来让机器人运行)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.