通过使用Discord API,我制作了一个简单的脚本,显示接收到某个通道的消息,并允许向该通道发送消息。但问题是input()正在保留程序,新消息在按下Enter键之前不会打印
为了解决这个问题,我想把Irssi做成一个前端,顶部显示消息,按钮部分允许我们输入消息
后端代码
from discord.ext import commands
channel_id = discord_channel_id
bot_token = bot_token
class MyClient(discord.Client):
async def on_ready(self):
global channel, msg
channel = discord.Client.get_channel(self, id=channel_id)
print(f'You are Connected on {channel}')
while True:
# Send message
msg = input('[You] >> ')
await channel.send(msg)
async def on_message(self, message):
# Don't respond to ourselves
if message.author == self.user:
return
if message.content:
global received
received = message.content
client = MyClient()
client.run(bot_token)
诅咒
import time
import curses
def main(stdscr):
status = 'connecting'
server = 'connecting'
channel = 'connecting'
online = 'connecting'
key = 0
stdscr.clear()
stdscr.refresh()
# Disable cursor blinking
curses.curs_set(0)
while (key != ord('~')):
# Initialization
stdscr.clear()
height, width = stdscr.getmaxyx()
# Status Bar
stdscr.addstr(f"Status: {status} Server: {server} Channel: {channel} Online: {online}", curses.A_REVERSE)
stdscr.chgat(-1, curses.A_REVERSE)
# Update the screen
stdscr.refresh()
key = stdscr.getch()
curses.wrapper(main)
我制作了一个简单的curses用户界面,但我不能像Irssi那样在按钮中添加输入窗口。我希望API收到的任何消息都打印在顶部,并使用输入按钮向服务器发送消息。但是我被困在这里了
getch
有一个超时,可以关闭(nodelay)或设置为一个小值(timeout)相关问题 更多 >
编程相关推荐