我试图使用Python的nextcord模块使用斜杠命令制造一个不和谐的机器人。我的invite链接同时使用bot和applications.commands作用域。
我从ping命令开始,使用我在网上找到的示例。我的代码如下所示:
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)我使用了一个函数来返回一个embed对象作为消息内容。
当在不和谐的情况下运行/ping时,它会返回"bot名称正在思考.“在最终改为“应用程序没有响应”之前。
我做错了什么?
发布于 2022-10-28 07:34:49
我已经通过this StackExchange post找到了答案。我需要使用embed=await embed(),如下所示:
await interaction.followup.send(embed=await embed(...))https://stackoverflow.com/questions/74051840
复制相似问题