Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
647 views
in Technique[技术] by (71.8m points)

python - Discord.py change channel title but keep id

At the moment I have a ticket system with a confirmation command that moves the channel to another category. Tickets can be of two types "orders" and "estimates" and the titles are like "order-id" "estimate-id".

This is the confirmation command:

    if ctx.channel.name.startswith('order') or ctx.channel.name.startswith('estimate'):
        oldname = ctx.channel.name
        category = discord.utils.get(ctx.guild.categories, name=config["confirm_category"])
        await ctx.channel.edit(name=f"{oldname}", category=category)
        await ctx.message.delete()
        await ctx.send(embed=emb)

This will verify the channel name if start with order or estimate but i would like that if the channel title starts with "estimate-id" to change into "order-id" and keep the actual id.

question from:https://stackoverflow.com/questions/65865762/discord-py-change-channel-title-but-keep-id

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You could use the split method to separate "estimate" and "id" like so:

if ctx.channel.name.startswith('order') or ctx.channel.name.startswith('estimate'):
    cat, id = ctx.channel.name.split('-')
    category = discord.utils.get(ctx.guild.categories, name=config["confirm_category"])
    await ctx.channel.edit(name=f"order-{id}", category=category)
    await ctx.message.delete()
    await ctx.send(embed=emb)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...