我正在撰寫命令,例如 $playlist,然后有 4 個變體。我想按下按鈕并打開鏈接,但出現此錯誤。我做錯了什么?
import discord
from discord.ext import commands
import config
from discord_components import Discord_Components, Button, ButtonStyle
intents = discord.Intents.all()
bot = commands.Bot(command_prefix='$')
@bot.command()
async def playlist(ctx):
await ctx.send('Hey! You can choose the playlist by choosing your mood:')
await ctx.send(('1. Test1\n2. Test2.\n3. Test3'\n4. Test4'),
components=[
[
Button(style=ButtonStyle.blue, label='Test1', custom_id='1'),
Button(style=ButtonStyle.green, label='Test2', custom_id='2'),
Button(style=ButtonStyle.red, label='Test3', custom_id='3'),
Button(style=ButtonStyle.gray, label='Test4', custom_id='4')
],
])
response = await bot.wait_for("button_click", check=lambda inter: inter.channel == ctx.channel)
if response.custom_id == '1':
await response.respond(
embed=discord.Embed(title='Open it ?'),
components=[
[
Button(style=ButtonStyle.red, label='No'),
Button(style=ButtonStyle.URL, label='Yep', url='https://www.youtube.com/')
]
]
)
bot.run('TOKEN')
uj5u.com熱心網友回復:
嘗試添加以下內容來初始化discord_components模塊:
@bot.event
async def on_ready():
DiscordComponents(bot)
也匯入DiscordComponents而不是Discord_Components.
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/371028.html
