2017-12-06 15 views
0

私はボットに引用符を保存する機能を作ろうとしています。基本的には、ユーザ、次に引用して、コマンドの引用を呼び出すことによって、保存する、例:discord.py client.send_messageはエラーを送信せずに無視されます

/引用私は、プログラムが引用符には問題を保存しないように管理して最高の

だ@Testが、 client.send_message()またはclient.say()(どちらも試しました)のいずれかが発生した場合、それらを完全に無視してエラーの発生やメッセージの送信を行わずにコードの残りの部分に移動します。私はsend_messageを両方ともコマンドの先頭にある文字列だけで置きますが、まだ何も送信しません(他のコマンドには全く問題はありません)。

コマンド:

@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() 

プリントがデバッグのために、ほとんどです(私は彼らがこのコマンドが何をしているか理解するのに役立つかもしれないので、私はそれらを維持したい考え出し

私はこれを期待しています。見積もりを棚に保存してからチャンネルに短い確認を送信しますが、うまくいきません。

ええ、あなたが何かをもっと知る必要があるかどうかを教えてください。ありがとう!

(編集) Aバージョンクリーンアップ:

@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() 

答えて

0

ボーイ私は愚かな気圧を感じていますが、私はちょうど私がそれらのひとつひとつの1の前に待っています忘れてしまったことに気づきました。だから誰かが似たような問題を抱えている場合は、忘れないようにしてください。

+0

母、古典的な間違い – ADug

関連する問題