我正在编码一个不和谐的bot,对于其中一个命令,我希望该bot对发送该命令的用户执行ping操作。我正在使用python 3.6.6
答案 0 :(得分: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')
答案 1 :(得分:0)
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')