前提、 実現したいこと
pythonのdiscord.pyのライブラリをpipからインストールしてbotを作っています。
botがログインしたら特定の人を特定のチャンネルにメンションするものをテストとして作っています。
しかし、メンバーやチャンネルなどの情報が取得できず、noneが帰ってきます。別でロールでも試したけどためでした。
取得できるときやできない時がありますが、その条件も分かりません。
いろいろ調べていますがまったくお手上げです。
環境:Windows11、Python3.9.12のdiscord1.7.3
よろしくお願いします。
出力・エラーメッセージ
None None login Ignoring exception in on_ready Traceback (most recent call last): File "C:\Users\hoge\AppData\Roaming\Python\Python39\site-packages\discord\client.py", line 343, in _run_event await coro(*args, **kwargs) File "c:\Users\hoge\hoge\discordbot_test.py", line 27, in on_ready await channel.send(f"{oneofmember.mention}") AttributeError: 'NoneType' object has no attribute 'send'
該当のソースコード
python
1print("running") 2import discord 3import asyncio 4 5from sympy import ff 6import dic 7import time 8import datetime 9 10TOKEN = 'token' 11 12client = discord.Client() 13intents=discord.Intents.all() 14 15channel_id = 878129657311002688 16channel = client.get_channel(channel_id) 17oneofmember_id = 736547076892000266 18oneofmember = client.get_user(oneofmember_id) 19print(channel) 20print(oneofmember) 21 22@client.event 23async def on_ready(): 24 print("login") 25 await channel.send(f"{oneofmember.mention}")
試したこと
await fetch_member(member_id)
や
Guild.get_member(member_id)
も試したけど同じ結果でした。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。