【发布时间】:2020-09-18 06:00:44
【问题描述】:
我有一个命令,它接受一个输入,然后根据该输入为票务系统删除一个频道。该命令现在可以删除通道,但删除方法无法识别“输出”变量。
我是不和谐的新手,提前抱歉。
if message.content.startswith(".close"):
verify_channel = client.get_channel(756238816511131773)
if not message.channel.id == verify_channel.id:
await message.delete()
else:
msg = message.content.split()
output = ""
for word in msg[1:]:
output += word
output += " "
guild = message.guild
channel = discord.utils.get(guild.text_channels, name=output)
await channel.delete()
运行命令时出错:
AttributeError: 'NoneType' object has no attribute 'delete'
【问题讨论】:
-
几乎但是通道名称由变量“输出”确定,新问题似乎是“输出”在搜索通道名称时不起作用,并且每个命令都有不同的通道名称时间,所以我不能使用默认频道名称
-
然后将你的问题编辑成你真正想要的,因为你问的是
is there a method of getting the channel ID from the name of the channel,如果你有其他与这个问题无关的问题,请创建一个新问题。 -
我更新了问题,你
-
您的原始代码/问题中存在问题,我在编写答案时没有注意到,但在
else语句之前未声明输出,因此它将超出范围,因此 @987654326 @ 到discord.utils.get()被调用时。该函数将找不到None通道并返回None。
标签: python discord discord.py discord.py-rewrite