我的 discord.py 命令有问题。我想发出 ping 命令,该命令将响应我的机器人的 ping。我的代码如下。
@bot.command()
async def ping(ctx):
await ctx.send(f"Pong :ping_pong:! Bot latency: **{round(bot.latency * 1000)}ms**"
我也尝试过像这样编写代码。
@client.command()
async def ping(ctx):
await ctx.send(f"Pong :ping_pong:! Bot latency: **{round(bot.latency * 1000)}ms**"
以上代码均无效。
答案 0 :(得分:0)
您是否在末尾添加了括号?
@bot.command() # set this to your bots variable
async def ping(ctx):
await ctx.send(f"Ping!\nLatency is **{round(bot.latency * 1000)}ms**!")
答案 1 :(得分:0)
我有这个命令并且我已经测试过它知道它有效..你可以试试:
@bot.command()
async def ping(ctx):
await ctx.send(f'My ping is** {round(bot.latency*1000)} Ms**')
顺便说一句,如果你已经定义了 bot 为客户端,请确保将 bot.latency 更改为 client.latency
答案 2 :(得分:0)
@client.command()
async def ping(ctx):
await ctx.send(f'Ping: {round(client.latency*1000)} ms')
这是我编写的代码,它运行良好。如果你不想使用@client,就用这个:
@bot.command()
async def ping(ctx):
await ctx.send(f'Ping: {round(bot.latency*1000)} ms')
您的代码的问题在于您忘记了 ms** 和 "之间的 )。
答案 3 :(得分:0)
embed = discord.Embed(
title="? Pong!",
description=f"The bot latency is {round(self.bot.latency * 1000)}ms.",
color=0x42F56C
)
await ctx.send(embed=embed)