【发布时间】:2021-11-24 14:07:41
【问题描述】:
单击按钮后,我的 Discord 机器人应将字符串复制到我的剪贴板。交互每次都失败:
import clipboard
from discord_components import Button, DiscordComponents
@client.command()
async def command(ctx, *args):
# do some stuff
await ctx.send('message', components=[Button(label='Copy to clipboard', custom_id="copy_btn")])
@client.event
async def on_button_click(interaction):
if interaction.custom_id == 'copy_btn':
try:
print('try to copy string')
clipboard.copy('my string')
await ctx.send('string copied')
except Exception as e:
print('failed to copy string to clipboard\n' + e)
当我使用command 时,我的机器人会向我发送带有按钮的消息。单击该按钮会将try to copy string 打印到我的控制台中,但不会复制“我的字符串”。养蜂也不例外。
pip install clipboard 成功。
pip install discord-components也一样
【问题讨论】:
标签: python discord discord.py clipboard