'ActionRow'对象没有属性'get'



我试图用按钮发送消息,但它给出了一个错误

在此之前,代码在一个文件中并且有效,但当我想将所有内容移动到cog时,出现了这个错误

File "/home/bot/.local/lib/python3.8/site-packages/discord_slash/client.py", line 1353, in invoke_command
await func.invoke(ctx, **args)
File "/home/bot/.local/lib/python3.8/site-packages/discord_slash/model.py", line 209, in invoke
return await self.func(self.cog, *args, **kwargs)
File "/home/bot/cogs/controlpanel.py", line 68, in clear
await ctx.send(embed=emb, components=[row])
File "/home/bot/.local/lib/python3.8/site-packages/discord_slash/context.py", line 215, in send
if components and not all(comp.get("type") == 1 for comp in components):
File "/home/bot/.local/lib/python3.8/site-packages/discord_slash/context.py", line 215, in <genexpr>
if components and not all(comp.get("type") == 1 for comp in components):
AttributeError: 'ActionRow' object has no attribute 'get'

我的代码:

class Controlpanel(commands.Cog):
def __init__(self, bot):
self.bot = bot
@cog_ext.cog_slash(name='controlpanel', description='Разместить панель управления сервером',
guild_ids=[928666080929542194])
@commands.has_permissions(administrator=True)
async def clear(self, ctx: SlashContext):
emb = discord.Embed(
description =
f"""
Панель управления сервером через дискорд
""",
colour = 0xffba42
)
emb.set_author(name='Панель управления')
row = ActionRow(
Button(
style=ButtonStyle.grey,
label='Статус',
custom_id='status'
),
Button(
style=ButtonStyle.green,
label='Запуск',
custom_id='on'
),
Button(
style=ButtonStyle.red,
label='Выключить',
custom_id='off'
),
Button(
style=ButtonStyle.green,
label='Перезапуск',
custom_id='restart'
),
Button(
style=ButtonStyle.red,
label='Убить',
custom_id='kill'
)
)
await ctx.send(embed=emb, components=[row])
@commands.Cog.listener()
async def on_button_click(self, inter):
if inter.component.id == "status":
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(host, port, username, password)
command = "pzserver status"
stdin, stdout, stderr = ssh.exec_command(command)
lines = stdout.readlines()
str1 = ''.join(lines)
print(time() + ' - ' + str1)
ssh.close()
await inter.reply(str1, ephemeral = True)
if inter.component.id == "on":
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(host, port, username, password)
command = "pzserver start"
ssh.exec_command(command)
ssh.close()
await inter.reply('Запускаю сервер! 📡', ephemeral = True)
if inter.component.id == "off":
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(host, port, username, password)
command = "pzserver stop"
ssh.exec_command(command)
ssh.close()
await inter.reply('Выключаю сервер! 📡', ephemeral = True)
if inter.component.id == "kill":
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(host, port, username, password)
command = "pzserver kill"
stdin, stdout, stderr = ssh.exec_command(command)
lines = stdout.readlines()
str1 = ''.join(lines)
print(time() + ' - ' + str1)
ssh.close()
await inter.reply(str1, ephemeral = True)
if inter.component.id == "restart":
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(host, port, username, password)
command = "pzserver restart"
ssh.exec_command(command)
ssh.close()
await inter.reply('Перезапускаю сервер! 📡', ephemeral = True)
my_channel = self.bot.get_channel(936698972561637496)
emb = discord.Embed(
description =
f"""
Сервер перезапуститься через 15 минут.
""",
colour = 0xffba42
)
emb.set_author(name = 'Перезапуск сервера!')
await my_channel.send(embed = emb)
def setup(bot):
bot.add_cog(Controlpanel(bot))
from discord_slash.utils.manage_components import create_actionrow, create_button
@cog_ext.cog_slash(name='controlpanel', description='Разместить панель управления сервером',
guild_ids=[928666080929542194])
@commands.has_permissions(administrator=True)
async def clear(self, ctx: SlashContext):
emb = discord.Embed(
description =
f"""
Панель управления сервером через дискорд
""",
colour = 0xffba42
)
emb.set_author(name='Панель управления')
row = create_actionrow(*[
create_button(
style=ButtonStyle.grey,
label='Статус',
custom_id='status'
),
create_button(
style=ButtonStyle.green,
label='Запуск',
custom_id='on'
),
create_button(
style=ButtonStyle.red,
label='Выключить',
custom_id='off'
),
create_button(
style=ButtonStyle.green,
label='Перезапуск',
custom_id='restart'
),
create_button(
style=ButtonStyle.red,
label='Убить',
custom_id='kill'
)
])
await ctx.send(embed=emb, components=[row])

components应以dict的形式交付。

  • 如果使用interaction.py 4.0.0~,则可以使用from interactions.models.component import ActionRow模块github

最新更新