I'm new to coding Discord bots in Python with the Nextcord library.
I ran into an issue with creating a transcript for a ticket.
The interaction to close the ticket failed due to what Python thinks is an issue.
Here is what my terminal said was the issue:
line 52, in close_ticket messages = await interaction.channel.history(limit=None, oldest_first=True).flatten
TypeError: object method can't be used in 'await' expression Here is my code:
@nextcord.ui.button(
label="Close Ticket", style=nextcord.ButtonStyle.red, custom_id="ticket_settings:red"
)
async def close_ticket(self, button:nextcord.ui.Button, interaction: nextcord.Interaction):
messages = await interaction.channel.history(limit=None, oldest_first=True).flatten
contents = [message.content for message in messages]
final = ""
for msg in contents:
msg = msg + "\n"
fianl = final + msg
with open('transcript.txt', 'w') as f:
f.write(final)
await interaction.response.send_message("Ticket is being closed.")
await interaction.channel.delete()
await interaction.user.send(f"Ticket closed in {interaction.channel.mention}. Here is the transcript.", file=nextcord.File(r'transcript.txt'))
os.remove("transcript.txt")
flatten
is a method (see this), you need to call it to use it in an await expression by adding()
at the end.To fix your issue, change this line:
Into this line:
Off topic to your issue, but there's also a small typo in your code: