如何让不和谐的机器人在命令中提及我和我提及的人

时间:2018-08-29 18:38:03

标签: python discord

我的意思示例(“ + slap @examplename”),然后该机器人将聊天“ @me slapped @examplename”,我似乎无法使其正常工作。

import discord
from discord.ext.commands import Bot

bot = Bot(command_prefix='+')

bot.command()
async def slap(self, member : discord.Member):
        """<member>: Be careful with this one."""
        await self.bot.say("*slaps {0} around a bit with a large, girthy trout*".format(member))


@bot.event
async def on_ready():
        print ("------------------------------------")
        print ("Bot Name: " + bot.user.name)
        print ("Bot ID: " + bot.user.id)
        print ("Discord Version: " + discord.__version__)
        print ("------------------------------------")
        await bot.change_presence(game=discord.Game(name='Created By Pluto'))


bot.run('')

1 个答案:

答案 0 :(得分:2)

我已删除了self,因为您似乎没有使用嵌齿轮:

bot.command(pass_context=True)
async def slap(member: discord.Member):
        """<member>: Be careful with this one."""
        await bot.say("{} slaps {}".format(ctx.message.author.mention, member.mention))

Member对象(包括message.author)具有mention属性,可让您轻松提及它们。