在"菜单中,用户选择了一个动作,我需要在"通道"中获取一条消息。用户在"日志"中选择的菜单。
我自己做不来
class log(discord.ui.Select):
def __init__(self):
options=[
discord.SelectOption(label="Логи сервера"),
discord.SelectOption(label="Логи входа и выхода участников")
]
super().__init__(placeholder="Выберите раздел.",max_values=1,min_values=1,options=options, custom_id="LOG")
async def callback(self, interaction: discord.Interaction):
if self.values[0] == "Логи сервера":
await interaction.response.edit_message(view=channel_log())
if self.values[0] == "Логи входа и выхода участников":
await interaction.response.edit_message(view=channel_log())
class channel(discord.ui.ChannelSelect):
def __init__(self):
super().__init__(placeholder="Выберите раздел.",channel_types=[discord.ChannelType.text], custom_id="HELP")
async def callback(self, interaction: discord.Interaction):
#for self.values[0] in logs():
print()
cur.execute(f'INSERT INTO logs (message_log) VALUES ({self.values[0].id})')
conn.commit()
await interaction.response.edit_message(f"{self.values[0].id}")
return
一个人在日志菜单中选择了一个特定的操作,如何在通道菜单中采取用户在日志中选择的操作?
您可以将消息作为ChannelLog
类的参数。像这样:
class Log(discord.ui.Select):
def __init__(self):
options=[
discord.SelectOption(label="Логи сервера"),
discord.SelectOption(label="Логи входа и выхода участников")
]
super().__init__(placeholder="Выберите раздел.",max_values=1,min_values=1,options=options, custom_id="LOG")
async def callback(self, interaction: discord.Interaction):
view = discord.ui.View()
view.add_item(ChannelLog(self.values[0]))
await interaction.response.edit_message(view=view)
class ChannelLog(discord.ui.ChannelSelect):
def __init__(self, message):
self.message = message
super().__init__(placeholder="Выберите раздел.",channel_types=[discord.ChannelType.text], custom_id="HELP")
async def callback(self, interaction: discord.Interaction):
#for self.values[0] in logs():
print()
cur.execute(f'INSERT INTO logs (message_log) VALUES ({self.values[0].id})')
conn.commit()
await interaction.response.edit_message(f"{self.values[0].id}")
# do something with the message
print(self.message)
return