@tree.command(name = "claim", description = "Provide our OrderID to claim your customer role!")
async def claim(interaction: discord.Interaction, OrderID: str):
if "-" or "_" in interaction.content:
# Extract the message after the command
claimed_message = interaction.content
MESSAGE = interaction.content
# Check if the message is long enough
if len(claimed_message) > 30:
# Open the file in read mode
with open('claimed_messages.txt', 'r') as f:
# Read each line of the file
for line in f:
# Check if the message is in the line
if claimed_message in line:
# Send a response to the user
await interaction.channel.send('This Order ID was already claimed before! If this is incorrect, open a support ticket.')
# Skip the rest of the code
return
# If the message was not found, continue with the rest of the code
# Create a cursor object
cursor = conn.cursor()
# Execute the SQL query
cursor.execute("SELECT * FROM orders WHERE slug = %s AND paid = true", (MESSAGE,))
# Fetch the results
results = cursor.fetchall()
if len(results) > 0:
# A matching row was found
# Give the user the role
role = discord.utils.get(interaction.guild.roles, name=ROLE_NAME)
await interaction.author.add_roles(role)
# Write the message and order ID to the file
with open('claimed_messages.txt', 'a') as f:
author_id = interaction.author.id
f.write(f"{claimed_message} , {author_id}\n")
await interaction.channel.send(f"You have claimed your customer role {interaction.author.mention}!")
else:
# No matching row was found
await interaction.channel.send('Order ID not found or order has not been paid.')
else:
await interaction.channel.send('Invalid Order ID!')```
Not sure why its not popping up in my slash command list
#Discord.py slash commands
1 messages · Page 1 of 1 (latest)
@tree.command(name = "test", description = "testing", guild = discord.Object(id = GUILD))
async def self(interaction: discord.Interaction, name: str):
await interaction.response.send_message(f"Hello {name}! I was made with Discord.py", ephemeral = True)```
I have this in there too as a different slash command and thats showing up just fine
Are both commands in the same file?
yes
I'm assuming somewhere in the file you have tree.run(...)?
class aclient(discord.Client):
def __init__(self):
super().__init__(intents=discord.Intents.default())
self.synced = False
self.added = False
async def on_ready(self):
await self.wait_until_ready()
if not self.synced:
await tree.sync(guild = discord.Object(id = GUILD))
self.synced = True
if not self.added:
self.add_view(ticket_launcher())
self.add_view(main())
self.added = True
print(f"We have logged in as {self.user}.")
client = aclient()
tree = app_commands.CommandTree(client)```
this is what else is in there
@jovial shuttle
Do you never call client.run(...)???
nono ofc yea at the end of my code
sorry didint quite understand
Ok, is it after both commands?
yes
Ok, so that's not the issue.
is it maybe because I didint specify a guild in the nonworking command?
should the GUILD variable have the id in '' or just the numbers?
Just the numbers
alr
ngl now both arent showing even when im trying to revert back lol
could it be that theyre still syncing? idk
@jovial shuttlenvm now back to the same problem where the test command works but not the other
I have no ideas for what could be broken.
np I just figured out what was wrong and now claim is showing
but now when running the command I recieve this error
What was wrong?
couldve been the guild thing or the uppercase "OrderID" because now it seems to show in the command list
but when using the command it shows the error I sent above
I think you need to do interaction.message.content
seems to get a attributeerror
went ahead and changed it too
oops
forgot to change one
Not sure why interaction.message would be None.
@tree.command(name = "claim", description = "Provide OrderID to claim your customer role!", guild = discord.Object(id = GUILD))
async def claim(interaction: discord.Interaction, orderid: str):
if "-" or "_" in interaction.message.content:
# Extract the message after the command
claimed_message = interaction.message.content
MESSAGE = interaction.message.content
# Check if the message is long enough
if len(claimed_message) > 30:
# Open the file in read mode
with open('claimed_messages.txt', 'r') as f:
# Read each line of the file
for line in f:
# Check if the message is in the line
if claimed_message in line:
# Send a response to the user
await interaction.channel.send('This Order ID was already claimed before! If this is incorrect, open a support ticket.')
# Skip the rest of the code
return
# If the message was not found, continue with the rest of the code
# Create a cursor object
cursor = conn.cursor()
# Execute the SQL query
cursor.execute("SELECT * FROM orders WHERE slug = %s AND paid = true", (MESSAGE,))
# Fetch the results
results = cursor.fetchall()
if len(results) > 0:
# A matching row was found
# Give the user the role
role = discord.utils.get(interaction.guild.roles, name=ROLE_NAME)
await interaction.author.add_roles(role)
# Write the message and order ID to the file
with open('claimed_messages.txt', 'a') as f:
author_id = interaction.author.id
f.write(f"{claimed_message} , {author_id}\n")
await interaction.channel.send(f"You have claimed your customer role {interaction.author.mention}!")
else:
# No matching row was found
await interaction.channel.send('Order ID not found or order has not been paid.')
else:
await interaction.channel.send('Invalid Order ID!')```
This is the updated code which I tried now and still getting attribute error
changed all of them here too
It's not an issue with your code. For some reason interaction.message isn't being set by whatever Discord API wrapper you're using.
Oh make sure your bot has the messages intent. I don't think it's a default intent and you will need to enable it in the developer portal!
already done unfotuently
its gotta be an issue with my code tho
since the first command works just fine its just that second long command thats having the issue
Is it? Your code that you shared looks to be using the default intents and isn't enabling the message intents.
well its working now here is the updated code with a new issue
@tree.command(name = "claim", description = "Provide our OrderID to claim your customer role!", guild = discord.Object(id = GUILD))
async def claim(interaction: discord.Interaction, orderid: str):
MESSAGE = str(orderid)
if isinstance(MESSAGE, str) and ( '-' in MESSAGE or '_' in MESSAGE):
print("Its working so far")
with open('claimed_messages.txt', 'r') as f:
for line in f:
if MESSAGE in line:
await interaction.channel.send('This Order ID was already claimed before! If this is incorrect, open a support ticket.')
return
# If the message was not found, continue with the rest of the code
cursor = conn.cursor()
# Execute the SQL query
cursor.execute("SELECT * FROM orders WHERE slug = %s AND paid = true", (MESSAGE,))
# Fetch the results
results = cursor.fetchall()
if len(results) > 0:
# A matching row was found
# Give the user the role
role = discord.utils.get(interaction.guild.roles, name=ROLE_NAME)
await interaction.author.add_roles(role)
# Write the message and order ID to the file
with open('claimed_messages.txt', 'a') as f:
author_id = interaction.author.id
f.write(f"{MESSAGE} , {author_id}\n")
await interaction.channel.send(f"You have claimed your customer role {interaction.author.mention}!")
else:
# No matching row was found
await interaction.channel.send('Order ID not found or order has not been paid.')
else:
await interaction.channel.send('Invalid Order ID!')```
Here's the docs for the discord.Interaction object https://discordpy.readthedocs.io/en/stable/interactions/api.html#discord.Interaction
There's no author attribute. You need to use one of the attributes listed in the docs.
looking through it and still coming blank, any ideas?