【问题标题】:discord.py client.send_message gets ignored without sending an errordiscord.py client.send_message 被忽略而不发送错误
【发布时间】:2017-12-06 13:26:42
【问题描述】:

我正在尝试为我的机器人创建一个函数来保存引号。基本上是通过用户调用命令quote然后保存引用,例如:

/quote @test 我是最棒的

该程序设法保存引号没有问题,但是当它遇到 client.send_message() 或 client.say() (我都尝试过)时,它似乎完全忽略它们并继续其余的代码不会引发错误或发送消息。我已经尝试在命令的开头同时添加一个 send_message 和一个仅包含一个字符串的 say,但它们仍然不发送任何内容(而其他命令完全没有问题)。

命令:

@bot.command()
async def quote(user : discord.Member, *words):#gets the user and then makes a list of all other words

    print(user.id)#a string of numbers
    print(testserver.get_member(user.id) == user)#evaluates to True, this is the reason i use user.id, so that its possible to create a member some other time.

    quoteshelf = shelve.open('quotes')
    quote = ''
    for i in range(len(words)):
        quote = quote + ' ' + words[i]

    bot.say('hi')#tests which have not been working
    bot.send_message(testserver, 'bye')

    if user.id in quoteshelf.keys():#checks if the user already exists in the file
        tempshelf = quoteshelf[user.id]#it isnt possible to append directly into the shelf (or at least it seems so)
        tempshelf.append({quote : getdate()})
        quoteshelf[user.id] = tempshelf

        bot.say('work pls')
        bot.send_message(user.server, 'Added: ' + ' to')
        print(1)
        print(quoteshelf[user.id])

    else:#if it isnt in the file then it will create a new one
        quoteshelf[user.id] = [{quote : getdate()}]
        print(2)
        print(quoteshelf[user.id])
        print(user.server)
        print(user.server == testserver)
        bot.say('ok sure')
        bot.send_message(user.server, 'Created directory for and added ')
        print(2)
    quoteshelf.close()

这些打印主要用于调试(我想我会保留它们,因为它们可能有助于理解这个命令在做什么。

我希望这可以保存带有货架的报价,然后向频道发送简短的确认,但是,第二部分我似乎无法完成。

所以,是的,我很欣赏任何正确方向的指示,如果您需要了解更多信息,请告诉我。谢谢!

(编辑) 清理后的版本:

@bot.command()
async def quote(user : discord.Member, *words):
    quoteshelf = shelve.open('quotes')
    quote = ''
    for i in range(len(words)):
        quote = quote + ' ' + words[i]

    if user.id in quoteshelf.keys():
        tempshelf = quoteshelf[user.id]
        tempshelf.append({quote : getdate()})
        quoteshelf[user.id] = tempshelf
        bot.say(user.server, 'Added: ' + quote + ' to ' + user.name)

    else:
        quoteshelf[user.id] = [{quote : getdate()}]
        bot.say('Created directory for ' + user.name + ' and added ' + quote)

    quoteshelf.close()

【问题讨论】:

    标签: python python-3.x discord.py


    【解决方案1】:

    男孩,我觉得 atm 很愚蠢,我刚刚意识到我已经忘记了在他们每个人之前等待。所以是的,如果有人有类似的问题,请确保你没有忘记等待......

    【讨论】:

    • 哈哈,经典错误
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-18
    • 1970-01-01
    • 2019-08-28
    • 2010-10-04
    • 1970-01-01
    • 1970-01-01
    • 2021-02-19
    相关资源
    最近更新 更多