这在以前是可行的,但突然不起作用了.这段代码的要点是,它在服务器中通过every个文本通道并对其进行核爆(基本上是重新克隆并删除旧通道,同时将重新克隆的通道保留在那里).然而,它现在只适用于少数频道,然后停止说:

 raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: NotFound: 404 Not Found (error code: 10003): Unknown Channel

现在,我对不和还不熟悉.py.因此,如果有人能给我看一下修复代码,我真的很感激,并附上一个小的解释,让我知道我做错了什么.我try 自己修复它,将倾斜的频道添加到列表中,将其附加到该列表中,如果它看到该频道,则跳过它,但代码不起作用.下面是我的代码,如果有人向我展示了它的修复代码以及它是如何工作的,我将不胜感激:

@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")

(我刚刚添加了一些东西来让机器人运行)

Python相关问答推荐

Python如何让代码在一个程序中工作而不在其他程序中工作

如果我已经使用了time,如何要求Python在12秒后执行另一个操作.sleep

在Python中管理多个OpenGVBO和VAO实例

如何在Python中使用ijson解析SON期间检索文件位置?

分组数据并删除重复数据

如何在图片中找到这个化学测试条?OpenCV精明边缘检测不会绘制边界框

Pandas 有条件轮班操作

使用@ guardlasses. guardlass和注释的Python继承

"使用odbc_connect(raw)连接字符串登录失败;可用于pyodbc"

Pandas计数符合某些条件的特定列的数量

使用NeuralProphet绘制置信区间时出错

计算天数

isinstance()在使用dill.dump和dill.load后,对列表中包含的对象失败

让函数调用方程

Pandas Data Wrangling/Dataframe Assignment

如何在两列上groupBy,并使用pyspark计算每个分组列的平均总价值

Python—压缩叶 map html作为邮箱附件并通过sendgrid发送

为什么在FastAPI中创建与数据库的连接时需要使用生成器?

从嵌套极轴列的列表中删除元素

为用户输入的整数查找根/幂整数对的Python练习