【问题标题】:How to mention from string on discord.py?如何从 discord.py 上的字符串中提及?
【发布时间】:2019-09-07 13:33:04
【问题描述】:

我正在设置一个 dicord 机器人,我在数据库上有用户名,所以我从一个连接到数据库的方法中获取用户名,并在字符串中返回用户名我想要从该字符串中提及我无法得到我去上班

我试过在文档上搜索,但我一点也不明白

async def job(channelid,message):
    print('init schedule')
    channel = client.get_channel(channelid)
    current_apps=current_app()
    usersapps=apps_user(current_apps["APPS"])
    counter=0
    while True:
        counter= counter + 1
        for i in range(0,len(usersapps)):
            await discord.client.send_message("{}".format(usersapps[i]['USER']),mentions=True)

        await asyncio.sleep(60) # task runs every 60 seconds 

我希望我的代码通过来自我的方法的字符串提及给定的用户

我遇到的错误

init schedule
Task exception was never retrieved
future: <Task finished coro=<job() done, defined at c:\Users\Nte\Desktop\rainbow army\bot.py:136> exception=TypeError("send() got an unexpected keyword argument 'mentions'",)>
Traceback (most recent call last):
  File "c:\Users\Nte\Desktop\rainbow army\bot.py", line 145, in job
    await discord.client.send_message("{}".format(usersapps[i]['USER']),mentions=True)
TypeError: send() got an unexpected keyword argument 'mentions'

【问题讨论】:

    标签: python-3.x discord.py


    【解决方案1】:

    我可以通过将用户 ID 保存到数据库中来提及用户,然后用我的方法获取它并发送这样的消息

    await channel.send("<@!{}>".format(usersapps[i]['USERID']))
    

    【讨论】:

      猜你喜欢
      • 2013-02-22
      • 2021-08-19
      • 2021-10-16
      • 1970-01-01
      • 2017-10-13
      • 2021-07-26
      • 2016-11-05
      • 2012-03-03
      • 1970-01-01
      相关资源
      最近更新 更多