Discord ticket bot won't open a ticket?
When I try to open a new ticket, the error message in Discord is: "This interaction failed" and the error message in the code editor is: "Traceback (most recent call last):
, line 427, in _scheduled_task
await item.callback(interaction)
, line 35, in ticket
await interaction.defer(
AttributeError: 'Button' object has no attribute 'defer'
import discord
from discord.ext import commands
TOKEN = "DISCORD-BOTTOKEN"
bot = commands.Bot(command_prefix="!",
intents=discord.Intents.all(),
status=discord.Status.dnd)
async def change_bot_activity():
activity = discord.Activity(type=discord.ActivityType.watching, name="")
await bot.change_presence(activity=activity)
@bot.event
async def on_ready():
print("Bot is Ready!")
await change_bot_activity()
@bot.command(name="ticket")
@commands.has_permissions(administrator=True)
async def ticket(ctx):
embed = discord.Embed(
description="Press the button to create a new ticket!"
)
view = CreateButton()
await ctx.send(embed=embed, view=view)
class CreateButton(discord.ui.View):
def __init__(self):
super().__init__(timeout=None)
@discord.ui.button(label="Create Ticket", style=discord.ButtonStyle.blurple, emoji="🎫", custom_id="ticketopen")
async def ticket(self, button: discord.ui.Button, interaction: discord.Interaction):
# Confirm user interaction
await interaction.defer()
category = discord.utils.get(interaction.guild.categories, id=)
for ch in category.text_channels:
if ch.topic == f"{interaction.user.id} DO NOT CHANGE THE TOPIC OF THIS CHANNEL":
await interaction.followup.send("You already have a ticket: {0}".format(ch.mention), ephemeral=True)
return
r1 = discord.utils.get(interaction.guild.roles, id=)
overwrites = {
interaction.guild.default_role: discord.PermissionOverwrite(read_messages=False),
r1: discord.PermissionOverwrite(read_messages=True, send_messages=True, manage_messages=True),
interaction.user: discord.PermissionOverwrite(read_messages=True, send_messages=True),
interaction.guild.me: discord.PermissionOverwrite(read_messages=True, send_messages=True)
}
channel = await category.create_text_channel(
name=str(interaction.user),
topic=f"{interaction.user.id} DO NOT CHANGE THE TOPIC OF THIS CHANNEL!",
overwrites=overwrites
)
await channel.send(embed=discord.Embed(
title="Create Ticket",
description="Do not ping team members",
color=discord.Color.green()
))
await interaction.followup.send(
embed=discord.Embed(
description="Create a new ticket {0}".format(channel.mention),
color=discord.Color.white()
)
)
bot.run(TOKEN)
If I see the right, the attribute "defer" does not exist .To solve the problem, you need to create this attribute. If it was to be inherited from the class discord.ui.View and there was a mistake, I wouldn't know.
best regards
Circumstances
I recommend a Bot e.g. Ticket Bot