我正在尝试创建一个不和谐的机器人,它的一部分读取 JSON 文件并从中创建一个表。当我测试它时,该表在 Visual Studio 中看起来很棒(屏幕截图的下半部分),但是当我将它作为不和谐的消息发送时,它会改变所有内容,看起来一团糟。有什么想法可以让不和谐消息与我在视觉工作室中看到的内容相匹配吗?
这是我目前拥有的代码
def get_list(dct):
table = PrettyTable()
for column in dct[0].keys():
table.add_column(column, [])
for item in dct:
row_list = []
for i in item.values():
row_list.append(i)
table.add_row(row_list)
return table
async def on_message(message):
if message.content.startswith('$LIST ToPlay'):
with open('GameListData.json', 'r+') as file:
data = json.load(file)
msg = get_list(data['ToPlay']).ToString()
await message.channel.send(msg)
Discord 不保持相同的格式,您需要使用代码块进行输出。
def get_list(dct):
table = PrettyTable()
for column in dct[0].keys():
table.add_column(column, [])
for item in dct:
row_list = []
for i in item.values():
row_list.append(i)
table.add_row(row_list)
return table
async def on_message(message):
if message.content.startswith('$LIST ToPlay'):
with open('GameListData.json', 'r+') as file:
data = json.load(file)
msg = get_list(data['ToPlay']).ToString()
await message.channel.send(f"```{msg}```")