Nextcord Slash Command Not Responding

Question:

I am trying to make a Discord bot with slash commands using Python’s nextcord module. My invite link uses both bot and applications.commands scopes.

I’ve started with a ping command using examples I’ve found online. My code looks like this:

import nextcord, os
from dotenv import load_dotenv
from nextcord.ext import commands
from flask import Flask
from threading import Thread

load_dotenv()

app = Flask('')
@app.route('/')
def home() -> str:
    return 'Running!'
def run() -> None:
    app.run(port=int(os.environ.get('PORT', 33507)))
def keep_alive() -> None:
    Thread(target=run).start()

TOKEN = os.environ['DISCORD_TOKEN']
description = '[bot name] [version]'
intents = nextcord.Intents.default()
intents.members = True

client = commands.Bot(command_prefix='/', description=description, intents=intents)

async def embed(title, description, reason) -> nextcord.Embed:
    return nextcord.Embed(
        title=title,
        description=description,
        color=0x00FF00
    ).set_author(
        name='[bot name] [version]',
        icon_url='[image link]'
    ).set_footer(
        text=f'This message was sent because {reason}.'
    )

@client.event
async def on_ready():
    print(f'Logged in as {client.user} (ID: {client.user.id})')
    await client.change_presence(activity=nextcord.Game(name='[version]'))

@client.slash_command(name='ping', description='Returns bot latency')
async def ping(interaction: nextcord.Interaction):
    await client.process_application_commands(interaction)
    await interaction.response.defer(with_message=True)
    await interaction.followup.send(embed=embed(':ping_pong: Pong!', f'{client.latency * 100} ms', f'{interaction.user} used the "ping" command'))

if __name__ == '__main__':
    keep_alive()
    client.run(TOKEN)

I’ve used a function to return an embed object to use as message content.

When running /ping on Discord, it returns "[bot name] is thinking…" before eventually changing to "The application did not respond".

What am I doing wrong?

Asked By: TurnipGuy30

||

Answers:

I’ve discovered the answer through this StackExchange post. I needed to use embed=await embed() as shown here:

await interaction.followup.send(embed=await embed(...))
Answered By: TurnipGuy30
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.