Discord.pyを使用していて、チャンネルに入力したユーザーのDiscordユーザーIDを取得しようとしています。
ユーザー ID は、開発者モードになってユーザー名を右クリックすると、 "copy id" というオプションがあるので、そこで確認できます。
現在のapiではこの方法が書かれていないのか、見逃してばかりです。
ドキュメントによると、User
クラスはユーザーIDを持つそうです。
http://discordpy.readthedocs.io/en/latest/api.html#user
そして、Member
は User
のサブクラスであること。
http://discordpy.readthedocs.io/en/latest/api.html#member
つまり、あるユーザーからメッセージを受け取った場合、そのIDを message.author.id
で取得することができます。
import discord
import asyncio
client = discord.Client()
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
@client.event
async def on_message(message):
print(message.author.id)
client.run('token')