小编exe*_*exe的帖子

get_user(id) 找不到用户 - 返回 None (self bot Discord.py)

我正在尝试使用自助机器人给自己发私信。我正在尝试在我的代码中使用该get_user()函数。

bot = commands.Bot(command_prefix='', self_bot=True)

counter = 0
userID = 695724603406024726

@bot.event
async def dm(userID):
    print('Running Function')
    global counter

    if counter <= 0:
        print('Finding user.')
        counter += 1

        user = bot.get_user(userID)

        print('user:',user)

        await user.send("Hello")
        print('message sent')

    return


bot.loop.create_task(dm(userID))
bot.run(token, bot=False)
Run Code Online (Sandbox Code Playgroud)

相反,我返回此错误:

  File "<ipython-input-1-90e5e962a6e9>", line 24, in dm
    await user.send("Hello")
AttributeError: 'NoneType' object has no attribute 'send'
Run Code Online (Sandbox Code Playgroud)

机器人无法找到用户并返回一个None值。我已经测试了多个 ID,但不确定问题是什么。

python discord.py

8
推荐指数
1
解决办法
8863
查看次数

如何在python中找到桌面路径

我是 os 库的新手,我想知道如何找到任何使用 windows 并使用python访问其桌面目录的用户的路径。提前致谢!

python operating-system

0
推荐指数
2
解决办法
2396
查看次数

正则表达式仅匹配英文字母文本

我试图编写正则表达式,仅匹配由Python中超过3个字母的英文字母文本组成的文本。我试过:

 regex = r'[a-z][a-z][a-z]+'
Run Code Online (Sandbox Code Playgroud)

但它不能过滤掉像这样的字符串

 how@@
Run Code Online (Sandbox Code Playgroud)

任何想法,将不胜感激:)

python regex nlp

0
推荐指数
1
解决办法
8839
查看次数

标签 统计

python ×3

discord.py ×1

nlp ×1

operating-system ×1

regex ×1