python - 如何让不和谐机器人提到我和我在命令中提到的人
问题描述
我的意思的例子(“+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('')
解决方案
我已删除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
允许您轻松提及它们的属性。
推荐阅读
- r - 在 R 向量中插入以前的日期
- c - 无法计算排序超过八个元素
- python - 如何在python中提取两个字符之间的子字符串?
- collections - 如何仅获取 Laravel 集合中的嵌套数据
- c - 如何使用 Openssl 使用存储在文件中的公钥验证 ECDSA 签名?
- aws-lambda - AWS-CDK:跨账户资源访问和资源参考
- c# - 使用不同下载方法时 GDI+ 在 System.Drawing.Image.Save 出现一般错误的原因是什么?
- c# - Entity Framework Core:如何将 2 个 COUNT 查询合并为一个
- rest - 使用 http.NewRequestWithContext() 创建的请求在传递给中间件时会丢失上下文
- python - ndarray/张量索引