尝试指定成员时出现位置错误 [英] Positional error when trying to specify member

查看:76
本文介绍了尝试指定成员时出现位置错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取一个成员名称而不是作者名称

Hi I'm trying to get a member name rather than the author name

我尝试了几种方法,例如 for member is message.server.members:会与服务器中的每个成员返回多个结果,并尝试使用 member:discord.Member 作为签名,从而产生错误:

I've tried a few methods like for member is message.server.members: which returned multiple results with every member in the server and tried member: discord.Member as a signature which produced an error:

这里是我正在使用的东西:

Heres what I'm working with:

async def on_message_delete(self, message):
    server = message.server
    author = message.author
    role =  get(server.roles, name="Powerbot")
    channel = get(message.server.channels, name="mod-log")
    time = datetime.utcnow()
    cleanmsg = message.content
    for i in message.mentions:
        cleanmsg = cleanmsg.replace(i.mention, str(i))
    fmt = '%H:%M:%S'
    name = author
    name = " ~ ".join((name.name, name.nick)) if name.nick else name.name
    if role not in author.roles:
        infomessage = "A message by {}, was deleted in {} by {}".format(message.author.mention, message.channel.mention, member,mention)
        delmessage = discord.Embed(description=infomessage, colour=discord.Color.purple(), timestamp=time)
        delmessage.add_field(name="Message:", value=cleanmsg)
        delmessage.set_footer(text="User ID: {}".format(message.author.id))
        delmessage.set_author(name=name + " message deleted.", icon_url=message.author.avatar_url)
        delmessage.set_thumbnail(url="http://i.imgur.com/fJpAFgN.png")
        try:
            await self.bot.send_message(channel, embed=delmessage)
        except:
            pass

该行专门位于member.mention所在的行。

The line specifically where member.mention is.

infomessage = {}的一条消息在{}中被{}删除了。format(message.author.mention,message。 channel.mention,member.mention)

示例输出:作者在频道中删除了作者的消息。

Example output: A message by author was deleted in channel by member.

如果有人可以帮助,将不胜感激。

If anyone could help that would be appreciated.

推荐答案

查看您所使用的Discord版本中无法删除该消息的人,因为稳定的discord.py不包含对审核日志的支持。 您需要重写discord.py 才能使用以下解决方案:

Viewing the person who deleted the message is not possible from the discord release that you’re using, since the stable discord.py does not contain support for audit logs. You will need discord.py rewrite to use the following solution:

@bot.event()
async def on_message_delete(msg):
    audits = await msg.guild.audit_logs(limit=10, action=discord.AuditLogAction.message_delete)
    async for audit in audits:
        try:
            await audit.target.get_message(msg.id)
        except discord.NotFound:
            continue      
        print(audit.user)
        break

这是假定即使删除邮件也保留邮件。如果上述方法不起作用,我想我们可以做的最好的事情是:

That’s under the assumption that messages are kept even after being deleted. If the above does not work, I guess the best we can do is:

@bot.event()
async def on_message_delete(msg):
    audits = await msg.guild.audit_logs(limit=10, action=discord.AuditLogAction.message_delete)
    audit = await audits.get(extra__channel=msg.channel)
    print(audit.user)

有关更多信息,请参见:

For further information, see:

https://discordapp.com/developers/docs / resources / audit-log

https://discordpy.readthedocs.io/en/rewrite/api.html#discord.AuditLogAction

这篇关于尝试指定成员时出现位置错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆