#python #button #discord #bots #nextcord
#питон #кнопка #Discord #боты #следующий корд
Вопрос:
поэтому я пытался создать бота, который объяснял бы систему экономики других ботов. Есть сообщение, которое появляется после нажатия определенной кнопки, и я хочу добавить еще одну кнопку к этому определенному сообщению. Это не работает, и я понятия не имею, почему.
Вот код:
from nextcord.ext import commands from nextcord.ui import view def Sbdrugs(self, ctx): embed = nextcord.Embed(title="Drugs", description="Drugs play an important role in Slotbot. So make sure to remember what they do.") embed.set_author(name = ctx.author.display_name, icon_url = ctx.author.avatar_url) embed.add_field(name = "Weed", value = "Weed can be smoked to restart cooldowns of almost everything including drink. (*Doesnt include drugs.*) Remember, weed is the currency of the black market.", inline = False) embed.add_field(name = "Drink", value = "Drinking beers basically restarts every cooldown except drugs.", inline = False) embed.add_field(name = "Steroids", value = "Dosing steroids makes you immune against the ~hex command and gives you access to the ~beatup command. Steroids even decrease the chance of getting scammed from 30% to 10%. It shortens the feed cooldown too.", inline = False) embed.add_field(name = "Opioids", value = "Make you immune against gun shots, makes you immune against beatup too and resets all cooldowns (except drugs) including smoke and drink.", inline = False) embed.add_field(name = "Anesthesia **AKA** Anes", value = "Stuns yourself but also makes others not possible to interact with your slotbot stats (bal, goose etc they cant check anything from you).", inline = False) embed.add_field(name = "LSD", value = "Shortens every cooldown to 15 secs but makes it very hard to do other cooldowns like bal or farm for example. LSD is mostly used for pill farming, constantly shooting people and for some other things but i currently cant remember.", inline = False) def Helpmeembed(self, ctx): embed = nextcord.Embed(title = "You called me...?", description= "What do you need help with?") #still working on this class SbDrugs(nextcord.ui.View): def __init__(self): super().__init__() self.value = None @nextcord.ui.button(label = "1", style = nextcord.ButtonStyle.blurple) async def helpb(self, button: nextcord.ui.Button, interaction: nextcord.Interaction): await interaction.response.send_message({Sbdrugs}, ephemeral=False) self.value = True self.stop() class Helpb(nextcord.ui.View): def __init__(self): super().__init__() self.value = None @nextcord.ui.button(label = "1", style = nextcord.ButtonStyle.blurple) async def helpb(self, ctx, button: nextcord.ui.Button, interaction: nextcord.Interaction): view = Sbdrugs() await interaction.response.send_message("What do you need help with on Slotbot?n**1. Drugs**", ephemeral=False, view = view) self.value = True self.stop() class Help(commands.Cog, name="Help"): def __init__(self, bot: commands.Bot): self.bot = bot @commands.command() async def helpme(self, ctx): view = Helpb() await ctx.send("Hey, I'm here, what do you need help with?nn**Slotbot**n*Press 1 for more information.*", view = view) await view.wait() if view.value is None: await ctx.send("Ay, where you at bruh") def setup(bot: commands.Bot): bot.add_cog(Help(bot))
Это ошибка, которую я получаю:
Ignoring exception in view lt;Helpb timeout=180.0 children=1gt; for item lt;Button style=lt;ButtonStyle.primary: 1gt; url=None disabled=False label='1' emoji=None row=Nonegt;: Traceback (most recent call last): File "C:UsersWindowsAppDataLocalProgramsPythonPython39libsite-packagesnextcorduiview.py", line 359, in _scheduled_task await item.callback(interaction) TypeError: helpb() missing 1 required positional argument: 'interaction'
Ответ №1:
Вы установили «ctx» на второй параметр, вы должны удалить его, вот так
class Helpb(nextcord.ui.View): def __init__(self): super().__init__() self.value = None @nextcord.ui.button(label = "1", style = nextcord.ButtonStyle.blurple) # async def helpb(self, ctx, button: nextcord.ui.Button, interaction: nextcord.Interaction): async def helpb(self, button: nextcord.ui.Button, interaction: nextcord.Interaction): view = Sbdrugs() await interaction.response.send_message("What do you need help with on Slotbot?n**1. Drugs**", ephemeral=False, view = view) self.value = True self.stop()