防止漫游器发送多条消息作为message.mentions

时间:2019-03-04 06:28:52

标签: python python-3.x discord discord.py

在此漫游器上,用户可以抢钱。我遇到的问题是,如果一个用户在发送的一条消息中标记了多个用户,则漫游器会响应每个被标记的人。只要标记了多个用户,用户就可以绕过if get_robbery(message.author) >= 20:检查。有没有办法确保漫游器仅响应第一个被标记的用户,而不响应每个被标记的用户?

编辑:更改了代码以反映更改。将for user in message.content更改为user = message.mentions[0],它可以正常工作。

if message.content.startswith('!rob'):
    if message.author.id in blacklist:
        await client.send_message(message.channel, "You are blacklisted for breaking the rules {}".format(message.author.mention))       
    else:
        if get_robbery(message.author) >= 20:
            await client.send_message(message.channel, "You can only rob 20 times every 30 minutes {}".format(message.author.mention))
        else:
            if message.author == user:
                await client.send_message(message.channel, "{} you can't rob yourself dummy".format(message.author.mention))
            else:
                if get_dollars(message.author) < 0:
                    await client.send_message(message.channel, "{} you can't even afford a gun <:papi:523340666269335552>".format(message.author.mention))
                else:   
                    user = message.mentions[0]
                    if (get_dollars(user)) < 1:
                        add_robbery(message.author, 1)
                        await client.send_message(message.channel, "{} is too broke to rob ".format(user.mention))
                    else:
                        user = message.mentions[0]
                        if (get_city(user)) != get_city(message.author):
                            await client.send_message(message.channel, "{} you can't rob {} because they are in **{}** ".format(message.author.mention, user.mention, get_city(user)))   
                        else:
                            if steal >= 3:
                                if get_dollars(message.author) < 20000 and (get_dollars(user)) < 20000:
                                    add_robbery(message.author, 1)
                                    remove_dollars(user, stealdollars)
                                    add_dollars(message.author, stealdollars)
                                    add_dollars_stolen(message.author, stealdollars)
                                    print("{} catches {} slippin and sticks them up for ${} <:BangBang:523383990825123840>".format(message.author.mention, user.mention, stealdollars))
                                    await client.send_message(message.channel, "{} catches {} slippin and sticks them up for ${} <:BangBang:523383990825123840>".format(message.author.mention, user.mention, stealdollars))
                                else:
                                    if get_dollars(message.author) >= 20000 and (get_dollars(user)) < 20000:
                                        add_robbery(message.author, 1)
                                        remove_dollars(user, stealdollars)
                                        add_dollars(message.author, stealdollars)
                                        add_dollars_stolen(message.author, stealdollars)
                                        print("{} catches {} slippin and sticks them up for ${} <:BangBang:523383990825123840>".format(message.author.mention, user.mention, stealdollars))
                                        await client.send_message(message.channel, "{} catches {} slippin and sticks them up for ${} <:BangBang:523383990825123840>".format(message.author.mention, user.mention, stealdollars))
                                    else:
                                        if get_dollars(message.author) < 20000 and (get_dollars(user)) >= 20000:
                                            add_robbery(message.author, 1)
                                            remove_dollars(user, stealdollars)
                                            add_dollars(message.author, stealdollars)
                                            add_dollars_stolen(message.author, stealdollars)
                                            print("{} catches {} slippin and sticks them up for ${} <:BangBang:523383990825123840>".format(message.author.mention, user.mention, stealdollars))
                                            await client.send_message(message.channel, "{} catches {} slippin and sticks them up for ${} <:BangBang:523383990825123840>".format(message.author.mention, user.mention, stealdollars))
                                        else: 
                                            if get_dollars(message.author) >= 20000 and (get_dollars(user)) >= 20000:
                                                add_robbery(message.author, 1)
                                                remove_dollars(user, stealdollarsx3)
                                                add_dollars(message.author, stealdollarsx3)
                                                add_dollars_stolen(message.author, stealdollarsx3)
                                                print("{} catches {} slippin and sticks them up for ${} <:BangBang:523383990825123840>".format(message.author.mention, user.mention, stealdollarsx3))
                                                await client.send_message(message.channel, "{} catches {} slippin and sticks them up for ${} <:BangBang:523383990825123840>".format(message.author.mention, user.mention, stealdollarsx3))
                            elif steal == 2:
                                if get_dollars(message.author) < 20000 and (get_dollars(user)) < 20000:
                                    add_robbery(message.author, 1)
                                    remove_dollars(message.author, stealrdollars)
                                    print("{} gets arrested trying to rob {} and has to post ${} bail ".format(message.author.mention, user.mention, stealrdollars))
                                    await client.send_message(message.channel, "{} gets arrested trying to rob {} and has to post ${} bail ".format(message.author.mention, user.mention, stealrdollars))

                                else:
                                    if get_dollars(message.author) >= 20000 and (get_dollars(user)) < 20000:
                                        add_robbery(message.author, 1)
                                        remove_dollars(message.author, stealrdollars)
                                        print("{} gets arrested trying to rob {} and has to post ${} bail ".format(message.author.mention, user.mention, stealrdollars))
                                        await client.send_message(message.channel, "{} gets arrested trying to rob {} and has to post ${} bail ".format(message.author.mention, user.mention, stealrdollars))

                                    else:
                                        if get_dollars(message.author) < 20000 and (get_dollars(user)) >= 20000:
                                            add_robbery(message.author, 1)
                                            remove_dollars(message.author, stealrdollars)
                                            print("{} gets arrested trying to rob {} and has to post ${} bail ".format(message.author.mention, user.mention, stealrdollars))
                                            await client.send_message(message.channel, "{} gets arrested trying to rob {} and has to post ${} bail ".format(message.author.mention, user.mention, stealrdollars))

                                        else:
                                            if get_dollars(message.author) >= 20000 and (get_dollars(user)) >= 20000:
                                                add_robbery(message.author, 1)
                                                remove_dollars(message.author, stealrdollarsx2)
                                                print("{} gets arrested trying to rob {} and has to post ${} bail ".format(message.author.mention, user.mention, stealrdollarsx2))
                                                await client.send_message(message.channel, "{} gets arrested trying to rob {} and has to post ${} bail ".format(message.author.mention, user.mention, stealrdollarsx2))
                            elif steal == 0:
                                add_robbery(message.author, 1)
                                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))

                            elif steal == 1:
                                if get_dollars(message.author) < 20000 and (get_dollars(user)) < 20000:
                                    add_robbery(message.author, 1)
                                    remove_dollars(message.author, robbeddollars)
                                    add_dollars(user, robbeddollars)
                                    add_dollars_stolen(user, robbeddollars)
                                    remove_grams(message.author, robbedgrams)
                                    add_grams(user, robbedgrams)
                                    add_grams_stolen(user, robbedgrams)
                                    print("{} kicks {}'s door down but is met with {}'s glock in their face and robbed of ${} and {} grams".format(message.author.mention, user.mention, user.mention, robbeddollars, robbedgrams))
                                    await client.send_message(message.channel, "{} kicks {}'s door down but is met with {}'s glock in their face and robbed of ${} and {} grams <:BangBang:523383990825123840> <:datboi:523383990825123840>".format(message.author.mention, user.mention, user.mention, robbeddollars, robbedgrams))

                                else:
                                    if get_dollars(message.author) >= 20000 and (get_dollars(user)) < 20000:
                                        add_robbery(message.author, 1)
                                        remove_dollars(message.author, robbeddollars)
                                        add_dollars(user, robbeddollars)
                                        add_dollars_stolen(user, robbeddollars)
                                        remove_grams(message.author, robbedgrams)
                                        add_grams(user, robbedgrams)
                                        add_grams_stolen(user, robbedgrams)
                                        print("{} kicks {}'s door down but is met with {}'s glock in their face and robbed of ${} and {} grams".format(message.author.mention, user.mention, user.mention, robbeddollars, robbedgrams))
                                        await client.send_message(message.channel, "{} kicks {}'s door down but is met with {}'s glock in their face and robbed of ${} and {} grams <:BangBang:523383990825123840> <:datboi:523383990825123840>".format(message.author.mention, user.mention, user.mention, robbeddollars, robbedgrams))
                                    else:
                                        if get_dollars(message.author) < 20000 and (get_dollars(user)) >= 20000:
                                            add_robbery(message.author, 1)
                                            remove_dollars(message.author, robbeddollars)
                                            add_dollars(user, robbeddollars)
                                            add_dollars_stolen(user, robbeddollars)
                                            remove_grams(message.author, robbedgrams)
                                            add_grams(user, robbedgrams)
                                            add_grams_stolen(user, robbedgrams)
                                            print("{} kicks {}'s door down but is met with {}'s glock in their face and robbed of ${} and {} grams".format(message.author.mention, user.mention, user.mention, robbeddollars, robbedgrams))
                                            await client.send_message(message.channel, "{} kicks {}'s door down but is met with {}'s glock in their face and robbed of ${} and {} grams <:BangBang:523383990825123840> <:datboi:523383990825123840>".format(message.author.mention, user.mention, user.mention, robbeddollars, robbedgrams))
                                        else:
                                            if get_dollars(message.author) >= 20000 and (get_dollars(user)) >= 20000:
                                                add_robbery(message.author, 1)
                                                remove_dollars(message.author, robbeddollarsx2)
                                                add_dollars(user, robbeddollarsx2)
                                                add_dollars_stolen(user, robbeddollarsx2)
                                                remove_grams(message.author, robbedgrams)
                                                add_grams(user, robbedgrams)
                                                add_grams_stolen(user, robbedgrams)
                                                print("{} kicks {}'s door down but is met with {}'s glock in their face and robbed of ${} and {} grams".format(message.author.mention, user.mention, user.mention, robbeddollarsx2, robbedgrams))
                                                await client.send_message(message.channel, "{} kicks {}'s door down but is met with {}'s glock in their face and robbed of ${} and {} grams <:BangBang:523383990825123840> <:datboi:523383990825123840>".format(message.author.mention, user.mention, user.mention, robbeddollarsx2, robbedgrams))

0 个答案:

没有答案