首页 > 解决方案 > 如何让不和谐机器人提到我和我在命令中提到的人

问题描述

我的意思的例子(“+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('')

标签: pythondiscord

解决方案


我已删除self,因为您似乎没有使用 cogs:

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允许您轻松提及它们的属性。


推荐阅读