【问题标题】:Ticket System - How to create an channel and move to a category in a different channel - discord.py票务系统 - 如何创建频道并移动到不同频道中的类别 - discord.py
【发布时间】:2021-06-03 13:18:51
【问题描述】:

所以我正在尝试创建一个票务系统,其中机器人创建一个频道并将其放入不同频道的类别中(例如:bot-cmds}

import discord
from discord.ext import commands

client = commands.Bot(command_prefix=">")

@client.command() #or bot
async def ticket(ctx):
    guild = ctx.guild
    category = discord.utils.get(guild.categories, name="category_name")
    if category is None:
        await guild.create_category_channel(name="category_name")

    ticket = await guild.create_text_channel(name=f"{ctx.author.name}#{ctx.author.discriminator}'s ticket")
    await ctx.send(f"Here's your ticket #{ticket}")
    await ctx.channel.edit(category=category)

但是它把 bot-cmds 放在了这个类别中,那么我该如何解决呢?

【问题讨论】:

    标签: python discord.py


    【解决方案1】:

    我猜你想在另一个频道类别中创建票务频道?

    如果这是正确的,你可以这样做

    import discord
    from discord.ext import commands
    
    client = commands.Bot(command_prefix=">")
    
    @client.command() #or bot
    async def ticket(ctx):
        guild = ctx.guild
        category = discord.utils.get(guild.categories, name="category_name") 
        # Gets the category of that channel (used your version so I don't know if this works)
    
        ticket = await ctx.guild.create_text_channel(f"{ctx.author.name}#{ctx.author.discriminator}'s ticket", category=category) 
        # Creates the text channel in the specified category
        await ticket.send(f"Here's your ticket #{ticket}")
    

    【讨论】:

    • 我想使用“名称”而不是 id,所以有其他方法吗?
    • 如果您的按名称获取类别的版本有效,则此代码现在应该有效
    • 我只是通过定义公会来编辑你的答案,它可以工作!
    • 对,我忘记了,只是想添加它,但是很好用!
    猜你喜欢
    • 2021-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-16
    • 1970-01-01
    • 2020-12-21
    • 2020-11-17
    • 2021-04-04
    相关资源
    最近更新 更多