机器人不提及消息

huangapple go评论69阅读模式
英文:

The bot does not mention messages

问题

我阅读了discord.py文档,并根据其编写了这段代码,但它没有生效。

@client.command()
async def ping(ctx):
    await ctx.send(f'Pong! 🚀\n主机延迟:{round(client.latency * 1000)} 毫秒!'.format(ctx.message.author.mention))
    print(f'尝试回应:Pong! 🚀\n主机延迟:{round(client.latency * 1000)} 毫秒!')
英文:

I read the discord.py documentation and wrote this code according to it, but it didn't work.

@client.command()
async def ping(ctx):
    await ctx.send(f'Pong! 🏓\\nHost Latency: {round (client.latency \* 1000)} ms!'.format(ctx.message.author.mention))
    print(f'TalkBack atemping: Pong! 🏓\\nHost Latency: {round (client.latency \* 1000)} ms!' )

答案1

得分: 1

why do you format a f string?!

await ctx.send(f'{ctx.author.mention} Pong! 🏓\nHost Latency: {round(client.latency * 1000)} ms!')

and the \ makes no sense you want a new line not a special character  ... so make
in the operation you dont use * only * you dont want the character ...

and the format problem is that there is nothing that can be formated there is no empty {} ...

英文:

hey here the first problem:

why do you format a f string?!

await ctx.send(f'Pong! 🏓\\nHost Latency: {round (client.latency \* 1000)} ms!'.format(ctx.message.author.mention))

should rather be

await ctx.send(f'{ctx.author.mention} Pong! 🏓\nHost Latency: {round(client.latency * 1000)} ms!')

and the \ makes no sense you want a new line not a special character  ... so make
in the operation you dont use * only * you dont want the character ...

and the format problem is that there is nothing that can be formated there is no empty {} ...

答案2

得分: -1

只获取作者的ID并执行

<@ctx.author.id>
英文:

Just get the authors ID and do

<@ctx.author.id>

答案3

得分: -1

I solved the problem myself

@client.command()
async def ping(ctx):
    await ctx.send(f'Pong! 🏳️\nHost Latency: {round(client.latency * 1000)} ms! {ctx.author.mention}')
    print('TalkBack attempting: Pong! 🏳️\nHost Latency: {round(client.latency * 1000)} ms!')

If anyone has a problem, use this method

英文:

I solved the problem myself

@client.command()
async def ping(ctx):
    await ctx.send(f'Pong! 🏓\nHost Latency: {round (client.latency * 1000)} ms! {(ctx.author.mention)}')
    print(f'TalkBack atemping: Pong! 🏓\nHost Latency: {round (client.latency * 1000)} ms!')

If anyone has a problem, use this method

huangapple
  • 本文由 发表于 2023年2月10日 16:00:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/75408327.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定