首页 > 解决方案 > 如何使用 discord.py 让 discord bot ping 用户

问题描述

我正在编写一个不和谐的机器人,对于其中一个命令,我希望机器人 ping 发送命令的用户。我正在使用 python 3.6.6

标签: pythondiscorddiscord.py

解决方案


这是一个示例,您可以如何 ping(提及)发送特定消息(命令)的用户:

import discord

class MyClient(discord.Client):
    async def on_ready(self):
        print('Logged on as', self.user)

    async def on_message(self, message):
        # don't respond to ourselves
        if message.author == self.user:
            return

        if message.content == '$the_ping_cmd':
            await message.channel.send('Pinging {}'.format(message.author.mention))

client = MyClient()
client.run('token')

推荐阅读