【问题标题】:Buttons in a message, discord消息中的按钮,不和谐
【发布时间】:2022-01-07 03:03:50
【问题描述】:

如何在欢迎消息中添加按钮? 按钮切换到另一个频道

@client.event
async def on_member_join(member):
    channel = client.get_channel(channelID)
    await channel.send(f'Hello')

【问题讨论】:

标签: python discord discord.py bots


【解决方案1】:

对于按钮,我使用 discord-py-slash-command 包 (documentation)。

from discord_slash.utils import manage_components
from discord_slash.model import ButtonStyle

@client.event
async def on_member_join(member):
    channel = client.get_channel(channelID)

    button = manage_components.create_button(style=ButtonStyle.URL, label="Your channel", url=f'https://discord.com/channels/{member.guild.id}/{channel.id}')
    action_row = manage_components.create_actionrow(button)
    
    await channel.send(content=f'Hello', components=[action_row])

这将创建一个按钮,将您转到您的频道。
链接包括: https://discord.com/channels/<server_id>/<channel_id>

Read more about Discord buttons

【讨论】:

  • 谢谢,但我收到一个错误,我从您发送的文档中导入了库 pip install -U discord-interactions 并没有帮助。 > ibb.co/k5xLMGk
  • 我需要安装 - discord_components ?
  • 然后 pip install discord-py-slash-command ?
  • @Dmitriy 你不必安装discord-interactions。你只需要discord-py-slash-command。安装它:pip install discord-py-slash-command
  • 我是新人,所以我问你。如何制作没有链接的按钮?只需点击它并转到频道
猜你喜欢
  • 2021-12-03
  • 2019-04-14
  • 2021-06-28
  • 2021-12-23
  • 1970-01-01
  • 1970-01-01
  • 2018-12-15
  • 2019-10-11
  • 2021-07-29
相关资源
最近更新 更多