简体   繁体   English

防止消息作者使用Discord.py命令提及自己

[英]Prevent message author from mentioning themselves with command Discord.py

Trying to prevent the user from mentioning themselves when they use the rob command. 试图防止用户在使用rob命令时提及自己。 I tried if message.author == user.mention but it doesn't work. 我尝试过if message.author == user.mention但它不起作用。

   if message.content.startswith('!rob'):
        try:
            if message.author == user.mention:
                 await client.send_message(message.channel, "{} you cant rob yourself! 👊".format(message.author.mention))
        except:
            pass
        else:
             if get_dollars(message.author) < 0:
                await client.send_message(message.channel, "{} you can't even afford a gun!".format(message.author.mention))
        finally:
            for user in message.mentions:
                if (get_dollars(user)) < 25:
                    await client.send_message(message.channel, "{} is too broke to rob 🤣".format(user.mention))
                elif steal == 1:
                    print("{} catches {} slippin and sticks them up for ${} 😨🔫".format(message.author.mention, user.mention, stealdollars))
                    await client.send_message(message.channel, "{} catches {} slippin and sticks them up for ${} 😨🔫".format(message.author.mention, user.mention, stealdollars))
                    remove_dollars(user, stealdollars)
                    add_dollars(message.author, stealdollars)
                elif steal == 2:
                    print("{} gets arrested trying to rob {} and has to post $250 bail 👮🚨".format(message.author.mention, user.mention))
                    await client.send_message(message.channel, "{} gets arrested trying to rob {} and has to post $250 bail 👮🚨".format(message.author.mention, user.mention))
                    remove_dollars(message.author, 250)
                elif steal >= 3:
                    print("{} kicks {}'s door down but doesn't find any cash 🤬".format(message.author.mention, user.mention))
                    await client.send_message(message.channel, "{} kicks {}'s door down but doesn't find any cash 🤬".format(message.author.mention, user.mention))

message.author is a discord.Member, user.mention isn't. message.author是不和谐的会员,user.mention不是。

Perhaps try something along the lines of: 也许尝试以下方法:

if message.author.id == user.id: # User IDs don't change.
    await client.send_message(ctx.message.channel, "You cannot rob yourself")

I hope this helped 希望这对您有所帮助

你可以做类似的事情

if message.author in message.mentions:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM