バージョン 0.6.0 で追加.

ログの設定

discord.py はPythonの logging モジュールを介してエラーやデバッグの情報を記録します。loggingモジュールが設定されていない場合は、エラーや警告が出力されないため、設定するとを強くおすすめします。loggingモジュールの設定は下記手順で簡単に実装が可能です。

import logging

logging.basicConfig(level=logging.INFO)

Placed at the start of the application. This will output the logs from discord as well as other libraries that use the logging module directly to the console.

The optional level argument specifies what level of events to log out and can be any of CRITICAL, ERROR, WARNING, INFO, and DEBUG and if not specified defaults to WARNING.

More advanced setups are possible with the logging module. For example to write the logs to a file called discord.log instead of outputting them to the console the following snippet can be used:

import discord
import logging

logger = logging.getLogger('discord')
logger.setLevel(logging.DEBUG)
handler = logging.FileHandler(filename='discord.log', encoding='utf-8', mode='w')
handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
logger.addHandler(handler)

This is recommended, especially at verbose levels such as INFO and DEBUG, as there are a lot of events logged and it would clog the stdout of your program.

詳細は、logging モジュールのドキュメントを参照してください。