我希望我的机器人能够在同一行中说出消息、提及用户,然后回复一条随机消息,而不是分三行。
这是我以前的方法:
if msg.startswith('respond')
await message.channel.send('alright then,')
await message.channel.send(message.author.mention)
await message.channel.send(random.choice(responses))
但是,这使它们都出现在同一行中,但我不知道如何将它们合并为一条单行。这是我多次失败的尝试之一:
if msg.startswith('respond'):
await message.channel.send ('alright then, <message.author.mention> <random.choice(responses)>')
(请不要取笑我的业余编码技能lmao)
最佳答案
假设你使用的是 python3+,你可以做 f-strings
if msg.startswith('respond'):
await message.channel.send(f'alright then, {message.author.mention} {random.choice(responses)}')
还有其他替代方法,例如格式字符串
if msg.startswith('respond'):
await message.channel.send('alright then, {} {}'.format(message.author.mention, random.choice(responses))
像这样的连接方法
if msg.startswith('respond'):
await message.channel.send('alright then, ' + message.author.mention + ' ' + random.choice(responses))
https://stackoverflow.com/questions/69023976/