Search code examples
pythondiscord.pynextcord

How Can i Fix this with Nextcord


Here is the full code of mute

@bot.slash_command()
async def mute(Interaction, member: nextcord.Member, duration: int = None):
    if not interaction.user.guild_permissions.mute_members:
        await interaction.response.send("Vi nemate dozvolu za mutiranje članova!", ephemeral=True)
        return
    muted_role = nextcord.utils.get(interaction.guild.roles, name="Muted")
    if not muted_role:
        muted_role = await interaction.guild.create_role(name="Muted")
        for channel in interaction.guild.channels:
            await channel.set_permissions(muted_role, send_messages=False)
    await member.add_roles(muted_role)
    await interaction.response.send_message(f'{member.mention} Je mutiran/a.')
    if duration:
        if duration <= 0:
            await interaction.response.send("Vreme trajanja mutea ne može biti manje od 0.")
            return
        await asyncio.sleep(duration)
        await member.remove_roles(muted_role)
        await interaction.response.send(f'{member.mention} Je unmutean/a posle {duration} sekundi.')
Ignoring exception in command <nextcord.application_command.SlashApplicationCommand object at 0x00000164BCDF7850>:
Traceback (most recent call last):
  File "C:\Users\M3C4V1C4\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\nextcord\application_command.py", line 918, in invoke_callback_with_hooks     
    await self(interaction, *args, **kwargs)
  File "C:\Users\M3C4V1C4\Desktop\botina\main.py", line 62, in mute
    await interaction.response.send(f'{member.mention} Je mutiran/a.')
          ^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'InteractionResponse' object has no attribute 'send'

The above exception was the direct cause of the following exception:

nextcord.errors.ApplicationInvokeError: Command raised an exception: AttributeError: 'InteractionResponse' object has no attribute 'send'

I tried to reinstall nextcord but does working...


Solution

  • async def mute(interaction:discord.Interaction)

    And in the last line change: await interaction.response.send(f'{member.mention} Je unmutean/a posle {duration} sekundi.') to: await interaction.response.send_message(f'{member.mention} Je unmutean/a posle {duration} sekundi.')