【问题标题】:Discord.py bot cannot ping, can someone show me what to do?Discord.py 机器人无法 ping,有人可以告诉我该怎么做吗?
【发布时间】:2019-04-24 01:41:10
【问题描述】:
import discord
import random
from discord.ext import commands

TOKEN='MyToken'

client = commands.Bot(command_prefix = '$')

@client.event
async def on_ready():
    await client.change_presence(game=discord.Game(name='the love spreading!', type=3))
    print('## Startup Complete ##')

@client.command()
async def love(user1: discord.Member,        
user2: discord.Member):
    love=random.randint(0,100)
    await client.say(':heart:' + str(love) + '%:heart: \n ' + str(user1) + ' + '+ str(user2))

client.run(TOKEN)    

嘿,它只是说“@TheAlexGamer#7679”而不是 ping,为什么? (我已经删除了将 @ 添加到 stackoverflow 的字符串的部分)

【问题讨论】:

    标签: python python-3.x discord discord.py


    【解决方案1】:

    您使用他们的不和谐 ID 来 ping 所以你可以使用这个代码

    @client.command()
    async def love(ctx):
        await ctx.send(f":heart: <@{ctx.author.id}>")
    

    它获取发送消息 id 的人,然后 ping 他们

    【讨论】:

      【解决方案2】:

      因为当您在 discord 上写 @TheAlexGamer#7679 时,您的 discord 客户端会自动将其更改为 &lt;@id_of_alexgmer&gt;

      要使用机器人 ping 某人,请使用 member.mention 属性。

      @client.command()
      async def love(user1: discord.Member,        
      user2: discord.Member):
          love=random.randint(0,100)
          await client.say(':heart:' + str(love) + '%:heart: \n ' + user1.mention + ' + '+ user2.mention)
      
      client.run(TOKEN)    
      

      【讨论】:

        猜你喜欢
        • 2014-11-23
        • 1970-01-01
        • 2021-11-16
        • 1970-01-01
        • 2021-09-05
        • 2013-02-20
        • 1970-01-01
        • 1970-01-01
        • 2021-12-08
        相关资源
        最近更新 更多