我正在尝试在我的机器人上的 Discord 上创建票证功能,我想知道如何在某个类别中检查文本频道是否已经存在,如果存在,则不会创建票证。
@bot.command()
async def new(ctx):
guild = ctx.message.guild
channel = discord.utils.get(guild.categories, id=404351895121952768)
if ctx.message.channel != bot.get_channel(402168280149655552):
tag = await bot.get_channel(402168280149655552).send("{}".format(ctx.message.author.mention))
wrongchannel_embed = discord.Embed(title="Error:",
description="Use my commands in the {} channel.".format(tag.channel.mention),
color=0xe73c24)
await ctx.send(embed=wrongchannel_embed)
elif discord.utils.get(guild.channels, name='{}-ticket'.format(ctx.message.author.name)):
failed_embed = discord.Embed(title="Failed to create a ticket",
description="You already have a ticket open, please don't try to open a ticket while you already have one.",
color=0xe73c24)
await ctx.send(embed=failed_embed)
else:
print(channel)
print(guild.categories)
overwrites = {
guild.default_role: discord.PermissionOverwrite(read_messages=False),
ctx.message.author: discord.PermissionOverwrite(read_messages=True)
}
ticket_create = await guild.create_text_channel(name='{}-ticket'.format(ctx.message.author.name),
overwrites=overwrites, category=channel)
ticket_embed = discord.Embed(title="Ticket",
description="{}\nPlease be patient. A member of our support team will be with you shortly.".format(
ctx.message.author.mention),
color=0x15a513)
ticket_embed.set_footer(text="Ticket requested by {}".format(ctx.message.author),
icon_url=ctx.message.author.avatar_url)
await ticket_create.send(embed=ticket_embed)
success_embed = discord.Embed(title="Ticket Creation",
description="{}, your ticket was successfully created: {1}.".format(
ctx.message.author.mention, ticket_create.mention),
color=0x15a513)
await ctx.send(embed=success_embed)
这是我创建票证的代码。我关注的重点是elif discord.utils.get(guild.channels, name='{}-ticket'.format(ctx.message.author.name)):
我知道我在那里做错了什么。我也试过:
elif "{}-ticket".format(ctx.message.author.name) in discord.utils.get(guild.channels, name="Tickets"):
但它没有用。
知道我能做什么吗?