Python 在var更改时发送dms,但获取AttributeError:';非类型';对象没有属性';发送';

Python 在var更改时发送dms,但获取AttributeError:';非类型';对象没有属性';发送';,python,discord,discord.py,Python,Discord,Discord.py,我正在尝试创建一个Discord bot,它从变量中获取用户id,并仅在私人消息中向这些人发送信息。 这就是我尝试过的 #pulling the id from a variable x = '' @bot.command(name='add') async def add(ctx): global x x = ctx.message.author.id GAMESTATE = 2 @tasks.loop(seconds=10) async def backgroun

我正在尝试创建一个Discord bot,它从变量中获取用户id,并仅在私人消息中向这些人发送信息。 这就是我尝试过的

#pulling the id from a variable
x = ''

@bot.command(name='add')
   async def add(ctx):
   global x
   x = ctx.message.author.id
   GAMESTATE = 2

@tasks.loop(seconds=10)
async def background():
    global GAMESTATE
    global x
    if GAMESTATE == 2:
        print('ssssss')
        user = bot.get_user(int(x))
        await user.send(message)
    else:
        pass

AttributeError:“非类型”对象没有属性“发送”

为了让您的bot从消息上下文中检索用户对象,您需要像这样给bot“成员”意图(我假设您已经启用了消息意图):

然而,为了简化使用,我建议:

intents = discord.Intents.all()
bot = commands.Bot(command_prefix='!', intents=intents)
因为大多数流行的机器人程序也需要所有的意图(管理员权限)。 大多数人不会介意,如果你需要优化/减少意图,我建议阅读:
更多信息

你在使用意图吗?我没有使用意图
intents = discord.Intents.all()
bot = commands.Bot(command_prefix='!', intents=intents)