LoginSignup
Doutleuf
@Doutleuf

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

Discord.py ephemeralメッセージの編集

解決したいこと

Discord.pyでEphemeralメッセージを編集したい

DiscordのTicketBotを作成しているのですが、Embedを使ったephemeralメッセージ

発生している問題・エラー


Traceback (most recent call last):
  File "C:\Users\galle\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\discord\ui\view.py", line 427, in _scheduled_task
    await item.callback(interaction)
  File "c:\Users\galle\Downloads\ploxhost\main.py", line 163, in close_ticket
    await msg.edit(embed=new_embed)
          ^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'edit'

または、問題・エラーが起きている画像をここにドラッグアンドドロップ

該当するソースコード

    @discord.ui.button(label='🔐¦チケットを終了', style=discord.ButtonStyle.red, row=1, custom_id='close_ticket')
    async def close_ticket(self, interaction: discord.Interaction, button: discord.ui.Button):

        embed=discord.Embed(title='チケット終了', color=discord.Colour.red())
        embed.add_field(name='', value='5秒後に自動でチケットを削除します。\nキャンセルしたい場合は下のボタンからキャンセルしてください。')
        msg=await interaction.response.send_message(embed=embed, ephemeral=True, view=Close_cansel())
        print(msg)
        await asyncio.sleep(5)

        check=[]
        with open('ticket_close', 'r', encoding='UTF-8') as file:
            for i in file:
                i=i.replace('\n', '')
                check.append(i)

        if str(interaction.channel.id) in check:
            check.remove(f'{interaction.channel.id}')
            with open('ticket_close', 'w', encoding='UTF-8') as file:
                for i in check:
                    file.write(f'{i}\n')
            new_embed = discord.Embed(title='チケット終了', color=discord.Colour.red())
            new_embed.add_field(name='', value='新しい内容をここに追加します。\nキャンセルしたい場合は下のボタンからキャンセルしてください。')

            # メッセージを編集
            await msg.edit(embed=new_embed)
0

1Answer

Your answer might help someone💌