【发布时间】:2020-09-17 13:55:15
【问题描述】:
嘿,我正在尝试接收包含多行的消息,在每行的开头和结尾添加文本,然后将这些行作为一条消息重新发送。主要问题是我在一条消息中发送多行时遇到问题。有人可以帮我吗?我将包括我想要的输出,所以你知道我的意思。非常感谢。
我目前使用的发送个人消息的代码
import discord
class MyClient(discord.Client):
async def on_ready(self):
print('Logged on as', self.user)
async def on_message(self, message):
if message.author == self.user:
return
channel = client.get_channel(754584125108912150) #change to your channel id
if message.channel.id == channel.id:
if "placeholder first line" in message.content.lower():
messagee = message.content.split('\n')
for line in messagee:
testt = "test_start "+line+" test_end"
await channel.send(testt)
client = MyClient()
client.run(TOKENHERE) #bot token here
当前正在发送的单个输出消息:
BOT_username Today at 9:41 AM
test_start apple first line test_end
BOT_username Today at 9:41 AM
test_start week test_end
BOT_username Today at 9:41 AM
test_start food test_end
BOT_username Today at 9:41 AM
test_start fork test_end
etc..
希望发送的单条消息:
BOT_username Today at 9:41 AM
test_start apple first line test_end
test_start week test_end
test_start food test_end
test_start fork test_end
【问题讨论】:
-
那么您要做的是获取一条消息,然后在它的前后添加一些内容,对吗?
标签: python python-3.x discord.py