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

2024-06-16 09:49:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我的意思是(“+slap@examplename”)这个机器人会在聊天中加入“@me slaped@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('')

Tags: importselfasyncdefbotwithawaitcommand
1条回答
网友
1楼 · 发布于 2024-06-16 09:49:20

我删除了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属性,允许您轻松地提及它们。在

相关问题 更多 >