【发布时间】:2021-12-09 12:35:18
【问题描述】:
我的 pycord 机器人中有一个帮助命令,它显示命令列表。这是要显示的嵌入:
helpEmbed = discord.Embed(title='BlazingBot Help', description='Hi, I\'m a bot made by BlazingLeaf#3982, but I can\'t do much yet because I\'m still under development')
这是视图的子类(当用户单击命令按钮时,它会切换到不同的嵌入和视图):
class helpView(View):
@discord.ui.button(label='Commands', style=discord.ButtonStyle.green)
async def command_callback(self, button, interaction):
await interaction.response.edit_message(embed=commandEmbed, view=commandView())
然后我有斜杠命令:
@bot.slash_command(name='help', description='Show a list of commands and get a link to the support server!', guild_ids=[861826763570151424])
async def help(ctx):
await ctx.interaction.response.send_message(embed=helpEmbed, view=helpView())
这很好用,但我还想添加一个 URL 按钮,该按钮可以指向我的机器人的支持服务器。我检查了 api,它提到你不能用 @discord.ui.button 装饰器创建一个 URL 按钮,你应该手动创建一个按钮。所以我在斜杠命令之前和视图的子类之后添加了这段代码:
supportServerButton = Button(label='Support Server', style=discord.ButtonStyle.gray, url='https://discord.com')
helpView().add_item(supportServerButton)
但是,我收到此错误:
loop = asyncio.get_running_loop()
RuntimeError: no running event loop
我该如何解决这个问题?
【问题讨论】:
-
您是否尝试过创建异步循环?
-
我没有,但我应该这样做吗?如果我应该,我应该怎么做?
-
你从哪里导入
Button?你在用discord_buttons吗? -
我是从 discord.ui 导入的