#Why 'return' doesn't work???

1 messages · Page 1 of 1 (latest)

ancient radish
#
    async def callback(self, inter: disnake.ModalInteraction):
        chatid = inter.text_values['chatid']
        name = inter.text_values['name']
        categoryid : int = inter.text_values['categoryid']
        bot.location_name = name

        thread = await inter.guild.fetch_channel(chatid)
        category = await bot.fetch_channel(categoryid)
        voice_channel = await category.create_voice_channel(name=name)
        existing_channel = disnake.utils.get(category.voice_channels, name=name)

        if category is None:
            embed = disnake.Embed(title='**Категория не найдена**', color=0xc73939)
            await inter.response.send_message(embed=embed, ephemeral=True)

        if voice_channel is None:
            voice_channel = await category.create_voice_channel(name=name)

        if existing_channel:
            embed = disnake.Embed(title='**Голосовой канал с таким названием уже существует**', color=0xc73939)
            await inter.response.send_message(embed=embed, ephemeral=True)
            return
        pass

        bot.category = category

        bot.voice = voice_channel

        embed = disnake.Embed(title='Успешно!', color=0x789789)
        await inter.response.send_message(embed=embed, ephemeral=True)

        msg = await thread.send(view=Btns())
        db.insert_table(msg.id, name, voice_channel.id)      
        ```
#

return doesn't working, instead of just sending embed, bot sends embed and creates voice_channel

pure wyvern
#

Becuase existing_channel is probably not truthy?

#

And I'm not sure what's going on with that random pass in the middle.

proven portal
#

interesting "bot vars"

pure wyvern
#

Kinda surprised you're not just getting an error.

categoryid : int = inter.text_values['categoryid'] that's a string, so
category = await bot.fetch_channel(categoryid) so this should give you NotFound exception

ancient radish
pure wyvern
#

Because it's coming from a modal payload.

ancient radish
#

: int

pure wyvern
#

That's a type hint.

#

That literally does nothing.

ancient radish
pure wyvern
#

?

ancient radish
#

yeah, whatever

#
        if existing_channel:
            embed = disnake.Embed(title='**Голосовой канал с таким названием уже существует**', color=0xc73939)
            await inter.response.send_message(embed=embed, ephemeral=True)
            return
pure wyvern
#

It's always 100% a string value.

ancient radish
# pure wyvern
        if category is None:
            embed = disnake.Embed(title='**Категория не найдена**', color=0xc73939)
            await inter.response.send_message(embed=embed, ephemeral=True)

        if voice_channel is None:
            voice_channel = await category.create_voice_channel(name=name)
ancient radish
pure wyvern
#

Try converting the categoryid to an actual int

#

cat_id = int(inter.text_values['categoryid'])