检测多个公会ID-Discord.py

时间:2020-10-20 22:55:49

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

此代码可用于将DM发送给加入公会的用户,但是它仅执行第一个if语句,而不是实际检查成员是否加入了公会。无论我加入guild1还是guild2,我都会从机器人上获得第一个DM。

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "require": {
        "php": "^7.3.0",
        "fideloper/proxy": "^4.2",
        "fruitcake/laravel-cors": "^2.0",
        "guzzlehttp/guzzle": "^7.0.1",
        "laravel/framework": "^8.0",
        "laravel/jetstream": "^1.0",
        "laravel/sanctum": "^2.6",
        "laravel/tinker": "^2.0",
        "livewire/livewire": "^2.0"
    },
    "require-dev": {
        "facade/ignition": "^2.3.6",
        "fzaninotto/faker": "^1.9.1",
        "mockery/mockery": "^1.3.1",
        "nunomaduro/collision": "^5.0",
        "phpunit/phpunit": "^8.5"
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    }
}

1 个答案:

答案 0 :(得分:0)

在您的示例中,您实际上并没有检查该成员所在的行会。 在discord.py(和类似的库)中,成员对象不是用户唯一的,而是代表用户在行会中的成员身份。

对于discord.py,公会作为属性“公会”存储在成员中:

guild_id = member.guild.id

然后您可以将成员的行会与其他行会ID进行比较:

if guild_id == 762921541204705321:
    # do stuff
elif guild_id == 1231254125151:
    # do other stuff