나는 discord.py를 사용하여 chat-bot을 만듭니다. 지금은 테스트 일 뿐이며 모든 코드는 1 파일에 있습니다.(discord.py) Client.send_message()가 메시지를 보내지 않습니다.
봇은 서버에 연결하고 느낌표 '!'로 시작하는 메시지를 수신합니다.
명령에 따라 두 가지 기능 중 하나를 호출합니다. 지금까지는 봇이 의도 한대로 작동합니다.
client = discord.Client()
@client.async_event
def on_message(message):
author = message.author
if message.content.startswith('!test'):
print('on_message !test')
test(author, message)
if message.content.startswith('!quit'):
print('on_message !quit')
quit(author, message)
그리고 이것은 이상한 곳입니다. quit-function이 호출되면 프로그램이 종료됩니다. 테스트 함수가 호출되면 아무 것도 수행하지 않습니다. 그것은 심지어 문자열을 인쇄하지 않습니다.
def test(author, message):
print('in test function')
yield from client.send_message(message.channel, 'Hi %s, i heard you.' % author)
def quit(author, message):
sys.exit()
내가 무엇이 누락 되었습니까? 어떤 도움을 주셔서 감사합니다.