2016-10-24 21 views
0

파이썬 3.5 용 확장 기능을 사용하여 사용자와 대화하기위한 Discord API를 사용할 수 있습니다.객체가 문자열로 변환 될 때 '모듈을 호출 할 수 없음'

확장은 채널의 고유 ID를 보유하는 Channel 객체를 포함하여 Python에 몇 가지 객체를 추가합니다.

이 코드 스 니펫에서; 어떤 문맥 내용

async def on_message(message): 
    if message.author==bot.user or message.channel!=CHANNEL: 
    print("Either not replying to myself, or recieved message from the wrong channel; '"+string(message.channel)+"' when I was expecting '"+(CHANNEL)+"'...") 
    return 

CHANNELbot 서버에 대한 연결이고, I는 봇과 인터페이스 할 대상 채널에 설정되는 상수이며 bot.user는의 ID를 포함하는 구성원 목적 chatbot.

if 문은 잘 작동하지만 message.channel을 문자열로 변환하면 다음 오류가 표시됩니다. TypeError: 'module' object is not callable. 왜 이런거야?

API 참조도 here 인 경우 자세한 내용을 제공 할 수 있습니다.

편집 : 조금 더 자세한 내용이 제공됩니다.

답변

0

import string과 같은 문구가 코드에 있는데 아마도 string을 함수처럼 호출 할 수 없기 때문에이 예외가 발생하는 string(message.channel)을 시도하고있는 것입니다. 따라서 귀하의 메시지를 포맷하여, 뭔가 간단하게하려고, 당신의 코드에서

>>> import string 
>>> string('hello') 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
TypeError: 'module' object is not callable 

: 여기

은 예입니다

msg = "Either not replying to myself, or received message from the wrong channel; '{}' when I was expecting '{}'..." 
print(msg.format(message.channel, CHANNEL)) 
0

를 내가 대답을 발견했습니다, 이것은 단지 사용하는 사람에 적용 discord.py;

채널 변수는 서로 직접 비교할 수 없습니다. 좋은 게임을 만들기 위해 message.channel.id != CHANNEL.id을 사용해야했습니다.

관련 문제