每个人都可以使用 Python 中复制文本的按钮

Button to copy text in Python available for everyone

我正在制作一个 Discord 机器人,为了让用户体验更好,我制作了一个按钮,允许用户复制嵌入字段的值。我在我的电脑上测试了代码,文本被复制了,但是当我试图点击我的 phone 中的按钮时,文本没有被复制。

有没有办法在每个 Discord 客户端(计算机客户端和移动客户端)上呈现此按钮?

不过我用的代码是这样的

from pyperclip import *

@ui.button(label="Copy ID", emoji="", style=ButtonStyle.green, custom_id="copy_id")
async def copy_id(self, button: ui.Button, interaction: Interaction):
    id = interaction.message.embeds[0].fields[4].value

    copy(id[1:-1])

您用于将文本发送到剪贴板的模块不再维护 (here is their github)。

我相信 () that the module Clipboard of Kivy 可能会解决你的问题。截至目前,它支持 Python 3.7 到 3.10。