Botアカウント作成¶
ライブラリとDiscord APIを使用するには、BotのDiscordアカウントを用意する必要があります。
Botのアカウント作成はとても簡単です。
まずは Discordのウェブサイト にログインしてください。
Navigate to the application page
Click on the "New Application" button.
Give the application a name and click "Create".
Create a Bot User by navigating to the "Bot" tab and clicking "Add Bot".
Click "Yes, do it!" to continue.
他人にBotの招待を許可する場合には、 Public Bot にチェックを入れてください。
また、必要なサービスを開発している場合を除いて、 Require OAuth2 Code Grant がオフになっていることを確認する必要があります。わからない場合は チェックを外してください 。
Copy the token using the "Copy" button.
This is not the Client Secret at the General Information page
警告
このトークンは、あなたのBotのパスワードと同義であることを覚えておきましょう。誰か他の人とトークンを共有することは絶対に避けてください。トークンがあれば、誰かがあなたのBotにログインし、サーバーから退出したり、サーバー内のすべてのメンバーをBANしたり、すべての人にメンションを送るなどといった悪質な行為を行える様になってしまいます。
可能性は無限なので、絶対に トークンを共有しないでください 。
If you accidentally leaked your token, click the "Regenerate" button as soon as possible. This revokes your old token and re-generates a new one. Now you need to use the new token to login.
以上です。 これでボットアカウントが作成され、そのトークンでログインできます。
Botを招待する¶
Botのユーザーを作成しましたが、現時点ではどのサーバーにも参加していない状態です。
If you want to invite your bot you must create an invite URL for it.
まずは Discordのウェブサイト にログインしてください。
Navigate to the application page
Click on your bot's page.
Go to the "OAuth2" tab.
Tick the "bot" checkbox under "scopes".
Tick the permissions required for your bot to function under "Bot Permissions".
Please be aware of the consequences of requiring your bot to have the "Administrator" permission.
Bot owners must have 2FA enabled for certain actions and permissions when added in servers that have Server-Wide 2FA enabled. Check the 2FA support page for more information.
Now the resulting URL can be used to add your bot to a server. Copy and paste the URL into your browser, choose a server to invite the bot to, and click "Authorize".
注釈
The person adding the bot needs "Manage Server" permissions to do so.
このURLを実行時に動的に生成したい場合は、 discord.Permissions
インターフェイスから discord.utils.oauth_url()
を使用できます。