如何让discord bot提到我和我在命令中提到的那个人

问题描述 投票:-1回答:1

我的意思的例子(“+ 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('')
python discord
1个回答
2
投票

我已经删除了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属性,可以让你轻松提及它们。

© www.soinside.com 2019 - 2024. All rights reserved.