如何使用 discord.py 让 discord bot ping 用户 [关闭]

Posted

技术标签:

【中文标题】如何使用 discord.py 让 discord bot ping 用户 [关闭]【英文标题】:How to make discord bot ping users using discord.py [closed] 【发布时间】:2020-02-26 14:16:32 【问题描述】:

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

【问题讨论】:

发送示例代码并详细描述您的问题。 【参考方案1】:

这是一个示例,您可以如何 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')

【讨论】:

【参考方案2】:
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(f"Pinging message.author.mention")

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

【讨论】:

以上是关于如何使用 discord.py 让 discord bot ping 用户 [关闭]的主要内容,如果未能解决你的问题,请参考以下文章