【发布时间】:2021-01-13 05:11:42
【问题描述】:
我使用了一些技巧,但它们不起作用。
例如:
@client.command()
async def ping(ctx):
await ctx.send('Pong! {0}'.format(round(bot.latency, 1)))
请帮忙!
【问题讨论】:
-
你能提供更多代码吗?你真的在运行机器人吗?
标签: discord.py
我使用了一些技巧,但它们不起作用。
例如:
@client.command()
async def ping(ctx):
await ctx.send('Pong! {0}'.format(round(bot.latency, 1)))
请帮忙!
【问题讨论】:
标签: discord.py
我使用了这个代码:
async def ping(ctx):
if round(client.latency * 1000) <= 50:
embed=discord.Embed(title="PING", description=f":ping_pong: Pingpingpingpingping! The ping is **{round(client.latency *1000)}** milliseconds!", color=0x44ff44)
elif round(client.latency * 1000) <= 100:
embed=discord.Embed(title="PING", description=f":ping_pong: Pingpingpingpingping! The ping is **{round(client.latency *1000)}** milliseconds!", color=0xffd000)
elif round(client.latency * 1000) <= 200:
embed=discord.Embed(title="PING", description=f":ping_pong: Pingpingpingpingping! The ping is **{round(client.latency *1000)}** milliseconds!", color=0xff6600)
else:
embed=discord.Embed(title="PING", description=f":ping_pong: Pingpingpingpingping! The ping is **{round(client.latency *1000)}** milliseconds!", color=0x990000)
await ctx.send(embed=embed)
确保您在顶部执行@client.command(),我将其删除是因为我使用了不同的命令处理程序。显然,我决定通过对它进行颜色编码并将所有内容嵌入其中来让它变得花哨。如果您想要一个返回 ping 且仅返回 ping 的简单命令,请尝试以下操作:
async def ping(ctx):
await ctx.send(f"{client.latency}")
没有比这更简单的了。如果这不起作用,请尝试:
async def ping(ctx):
await ctx.channel.send(f"{client.latency}")
和往常一样,不要忘记在顶部添加@client.command()。
【讨论】: