'Updated - Create text_channel in specific category
So I am trying to create a text channel in a specific category. It worked but suddenly it's not.
This is my Code:
import discord
from discord.ext import commands
from discord.utils import get
from discord.ui import *
intents = discord.Intents().all()
token = "_TOKEN_"
pref = "§"
bot = commands.Bot(command_prefix=pref,help_command=None,intents=intents)
@bot.event
async def on_interaction(res):
chan = discord.utils.get(res.guild.text_channels, name=f"ticket-{res.author.name.lower()}")
if res.channel.id == _CHANNEL_ID_:
if chan != None:
return await res.respond(content="Sie haben bereits ein offenes Ticket!")
maincategory = discord.utils.get(res.guild.categories,name="Tickets")
overwrites = {
res.guild.me: discord.PermissionOverwrite(view_channel=True),
res.author: discord.PermissionOverwrite(view_channel=True),
res.guild.default_role: discord.PermissionOverwrite(view_channel=False)
}
overwrites[_ROLE_ID_] = discord.PermissionOverwrite(view_channel=True)
overwrites[_ROLE_ID_] = discord.PermissionOverwrite(view_channel=True)
channel = await res.guild.create_text_channel(f"ticket-{res.author.name}",category=maincategory, overwrites=overwrites)
embed = discord.Embed(title="Willkommen auf deinem Ticket",description=f"Hier kannst du mit den Admins und dem Support privat schreiben. Mit **{pref}close** kannst dieses Ticket schließen, wenn dein Anliegen geregelt ist.",color=0x00aaff)
await channel.send(embed=embed)
await res.respond(content="Ticket erstellt!")
@bot.command(pass_context=True)
@commands.has_role(_ROLE_)
async def ticket(ctx):
embed = discord.Embed(title = 'Support Request',color = 0x00aaff)
embed.add_field(name="Wenn du: ",value="- Probleme auf dem Server hast.\n- Vorschläge für den Server hast.\nZum Erstellen eines Tickets drück den Button unter der Nachricht.")
embed.set_footer(text="Ticket System")
button = Button(label="Erstelle ein Ticket!",style=discord.ButtonStyle.green, emoji="📩")
bot.run(token)
And this is my error:
Traceback (most recent call last):
File "C:\Users\ofcha\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "c:\Users\ofcha\OneDrive - Berufskolleg Bergisch Gladbach\Anwendungsentwicklung\Private\Discord\testbot2\discordbot.py", line 288, in on_button_click
channel = await res.guild.create_text_channel(f"ticket-{res.author.name}",category=maincategory, overwrites=overwrites)
File "C:\Users\ofcha\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\guild.py", line 948, in create_text_channel
data = await self._create_channel(name, overwrites, ChannelType.text, category, reason=reason, **options)
File "C:\Users\ofcha\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\guild.py", line 844, in _create_channel
'id': target.id
AttributeError: 'int' object has no attribute 'id'
I don't get it. I tried to get solutions for my problem but nothing solved. Now I am trying to get help, pls.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|