Hi I'm trying to get a member name rather than the author name
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
The line specifically where member.mention is.
infomessage = "A message by {}, was deleted in {} by {}".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.
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:
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:
For further information, see:
https://discordapp.com/developers/docs/resources/audit-log
https://discordpy.readthedocs.io/en/rewrite/api.html#discord.AuditLogAction
I'm pretty sure that the client isn't informed about who deleted the message, just the fact that it was deleted. The
message
object itself doesn't hold that information, and theRawMessageDeleteEvent
from the rewrite branch doesn't have it either.I'm not super familiar with the underlying Discord API, but the
Message Delete
gateway event looks to be whatdiscord.py
receives when a message is deleted, and it doesn't mention anything about the identity of the deleter.