机器人不提及消息

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

The bot does not mention messages

问题

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

  1. @client.command()
  2. async def ping(ctx):
  3. await ctx.send(f'Pong! 🚀\n主机延迟:{round(client.latency * 1000)} 毫秒!'.format(ctx.message.author.mention))
  4. 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.

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

答案1

得分: 1

why do you format a f string?!

  1. 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?!

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

should rather be

  1. 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并执行

  1. <@ctx.author.id>
英文:

Just get the authors ID and do

  1. <@ctx.author.id>

答案3

得分: -1

I solved the problem myself

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

If anyone has a problem, use this method

英文:

I solved the problem myself

  1. @client.command()
  2. async def ping(ctx):
  3. await ctx.send(f'Pong! 🏓\nHost Latency: {round (client.latency * 1000)} ms! {(ctx.author.mention)}')
  4. 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:

确定