Discord.py机器人无法ping通,有人可以告诉我该怎么做吗?

时间:2018-11-21 13:14:37

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

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的字符串中的部分)

1 个答案:

答案 0 :(得分:0)

因为在discord上写入@TheAlexGamer#7679时,discord客户端会自动将其更改为<@id_of_alexgmer>

要使用漫游器对某人执行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)