チケットシステムについてです。
id エラーの解除方法がわかりません。
select menu 選択まではdiscordで正常に動作します。
select menuを選択した後に下記のエラーが出てinteractionエラーが発生します。
エラーを改善し、カテゴリー内にチャンネルを作成するにはどうしたら良いか。
詳しい方教えてください。
エラーコード
Traceback (most recent call last):
File "/home/runner/tiket/venv/lib/python3.10/site-packages/discord/ui/view.py", line 427, in _scheduled_task
await item.callback(interaction)
File "main.py", line 29, in my_callback
channel = await guild.create_text_channel(f"{interaction.user.name}-ticket",category=category, overwrites=overwrites)
File "/home/runner/tiket/venv/lib/python3.10/site-packages/discord/guild.py", line 1369, in create_text_channel
data = await self._create_channel(
File "/home/runner/tiket/venv/lib/python3.10/site-packages/discord/guild.py", line 1227, in _create_channel
payload = {'allow': allow.value, 'deny': deny.value, 'id': target.id}
AttributeError: 'NoneType' object has no attribute 'id'
import discord
from discord.ui import Button, View,Select
from discord.ext import commands
token = ""
bot = commands.Bot(command_prefix="?", intents=discord.Intents.all())
async def ticketcallback(interaction):
guild = interaction.guild
role = discord.utils.get(guild.roles, name="MODERATER")
overwrites = {
guild.default_role: discord.PermissionOverwrite(view_channel = False),
interaction.user: discord.PermissionOverwrite(view_channel = True),
role: discord.PermissionOverwrite(view_channel = True)
}
select = Select(options=[
discord.SelectOption(label="Help ticket",value="01",emoji="✅",description="Open a Help ticket"),
discord.SelectOption(label="Other ticket",value="02",emoji="❌",description="Open a tiket in other section")
])
async def my_callback(interaction):
if select.values[0] == "01":
category = guild.get_channel(guild.categories, name="tickets")
channel = await guild.create_text_channel(f"{interaction.user.name}-ticket",category=category, overwrites=overwrites)
await interaction.response.send_message(f"created tiket - <#{channel.ID}",ephemeral=True)
await channel.send("Help?")
elif select.values[0] == "02":
category = discord.utils.get(guild.categories, name="Other tikets")
channel = await guild.create_text_channel(f"{interaction.user.name}-ticket",category=category, overwrites=overwrites)
await interaction.response.send_message(f"created tiket - <#{channel.ID}",ephemeral=True)
await channel.send("Help?")
select.callback = my_callback
view = View(timeout = None)
view.add_item(select)
await interaction.response.send_message("Option bloe",view=view, ephemeral=True)
@bot.command()
async def ticket(ctx):
button = Button(label="チケット作成",style=discord.ButtonStyle.green)
button.callback = ticketcallback
view = View(timeout=None)
view.add_item(button)
await ctx.send("Open ticket",view=view)
bot.run(token)