@Bot.command(pass_context= True)
async def complete(ctx):
guild = ctx.message.guild
id_admin = discord.Role.id=658306078928273408
overwrites = {
id_admin: discord.PermissionOverwrite(send_messages=True),
guild.me: discord.PermissionOverwrite(read_messages=True),
}
await guild.delete_text_channel(discord.TextChannel.name)
我在Discord API中找不到正确的属性。
我应该使用什么属性来删除编写命令的通道?
Error: AttributeError: 'Guild' object has no attribute 'delete_text_channel'
答案 0 :(得分:1)
您可以将GuildChannel.delete
方法与GuildChannel
的任何子类一起使用。
您可以使用TextChannel
来检索发送邮件的Context.channel
。
您不应修改discord.py类的属性,而应引用这些类的特定对象/实例的属性。
答案 1 :(得分:0)
@ Harmon758很好地说明了如何调用delete命令,但是对于不熟悉Discord API的任何人,这是我处理删除通道请求的方式:
@bot.command(name='delete-channel', help='delete a channel with the specified name')
async def delete_channel(ctx, channel_name):
# check if the channel exists
existing_channel = discord.utils.get(guild.channels, name=channel_name)
# if the channel exists
if existing_channel is not None:
await existing_channel.delete()
# if the channel does not exist, inform the user
else:
await ctx.send(f'No channel named, "{channel_name}", was found')