【发布时间】:2020-02-26 14:16:32
【问题描述】:
我正在编写一个 discord 机器人,对于其中一个命令,我希望机器人 ping 发送该命令的用户。我正在使用 python 3.6.6
【问题讨论】:
-
发送示例代码并详细描述您的问题。
标签: python discord discord.py
我正在编写一个 discord 机器人,对于其中一个命令,我希望机器人 ping 发送该命令的用户。我正在使用 python 3.6.6
【问题讨论】:
标签: python discord discord.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')
【讨论】:
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')
【讨论】: