AttributeError: 'NoneType' 对象没有属性 'send' discord.py

时间:2021-03-24 21:28:00

标签: python discord discord.py

我正在尝试使用命令 .dmtest 向特定用户发送 dm,但是每当我运行该命令时,我都会收到标题中提到的错误 这是我的代码:

import discord

from discord.ext import commands
import os
import requests
import asyncio



from keep_alive import keep_alive

client = discord.Client()

@client.event
async def on_ready():
  print('We have logged in as {0.user}'.format(client))



@client.event
async def on_message(message):
  if message.author == client.user:
    return

  if message.content.startswith('.dmtest'):
    user = client.get_user(384185404510961664)
    # await message.author.send(...)
    await message.channel.send('test worked')
    await user.send('a')

keep_alive()
client.run(os.getenv('TOKEN'))

错误:

line 78, in on_message
  await user.send('a')
AttributeError: 'NoneType' object has no attribute 'send'

1 个答案:

答案 0 :(得分:1)

稍微玩弄你的代码后,我发现在用 import numpy as np import matplotlib.pyplot as plt from scipy.stats import multivariate_normal def points_to_gaussian_heatmap(centers, height, width, scale): gaussians = [] for y,x in centers: s = np.eye(2)*scale g = multivariate_normal(mean=(x,y), cov=s) gaussians.append(g) # create a grid of (x,y) coordinates at which to evaluate the kernels x = np.arange(0, width) y = np.arange(0, height) xx, yy = np.meshgrid(x,y) xxyy = np.stack([xx.ravel(), yy.ravel()]).T # evaluate kernels at grid points zz = sum(g.pdf(xxyy) for g in gaussians) img = zz.reshape((height,width)) return img W = 800 # width of heatmap H = 400 # height of heatmap SCALE = 64 # increase scale to make larger gaussians CENTERS = [(100,100), (100,300), (300,100)] # center points of the gaussians img = points_to_gaussian_heatmap(CENTERS, H, W, SCALE) plt.imshow(img); plt.show() 替换 await user.send('a') 后我得到了 DMed "a"。进行更改后,行 await message.author.send('a') 是不必要的,可以删除。

编辑:由于这不是您要查找的内容,我在互联网上搜索发现您只需要将 user = client.get_user(384185404510961664) 替换为 client.get_user(id)