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

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

【问题讨论】:

  • 发送示例代码并详细描述您的问题。

标签: python discord discord.py


【解决方案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')
    

    【讨论】:

      猜你喜欢
      • 2022-01-09
      • 2018-07-29
      • 1970-01-01
      • 1970-01-01
      • 2020-02-23
      • 2020-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多