外部のユーザーにDMを送信したい
サーバー内のユーザーであれば
Python
1 user = bot.get_user(userid) 2 await user.send('テストメッセージ')
これで送信できるのですが、サーバー外の人だとこれでは送信できませんでした。調べてもサーバー内であれば大量に情報が出てくるのですが、外部はわからなくてお力をお貸しいただきたくここに投稿しております。
全文
Python
1import discord 2import random 3from discord.ext import commands 4from discord.utils import get 5 6token = "TOKEN" 7bot = commands.Bot(command_prefix = '.') 8 9@bot.event 10async def on_ready(): 11 print('Ready') 12 13@bot.command(pass_context=True) 14async def dm(ctx): 15 user = bot.get_user(userid) 16 await user.send('Hey guys! We have a gift for you!') 17
外部に送信したときのエラー
Error
1Ignoring exception in command dm: 2Traceback (most recent call last): 3 File "D:\LAB\venv\lib\site-packages\discord\ext\commands\core.py", line 83, in wrapped 4 ret = await coro(*args, **kwargs) 5 File "D:/LAB/vote.py", line 41, in dm 6 await user.send('Hey guys! We have a gift for you!') 7AttributeError: 'NoneType' object has no attribute 'send' 8 9The above exception was the direct cause of the following exception: 10 11Traceback (most recent call last): 12 File "D:\LAB\venv\lib\site-packages\discord\ext\commands\bot.py", line 892, in invoke 13 await ctx.command.invoke(ctx) 14 File "D:\LAB\venv\lib\site-packages\discord\ext\commands\core.py", line 797, in invoke 15 await injected(*ctx.args, **ctx.kwargs) 16 File "D:\LAB\venv\lib\site-packages\discord\ext\commands\core.py", line 92, in wrapped 17 raise CommandInvokeError(exc) from exc 18discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'send'
宜しくおねがいします。
環境
Windows 10 x64
PyCharm
Discord rewrite 1.4.1

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/08/11 09:34
2020/08/11 09:37 編集
2020/08/11 09:48
2020/08/11 10:18
2020/08/11 15:13