python - 如何将值合并到 discord.py 中的一条消息中

我希望我的机器人能够在同一行中说出消息、提及用户,然后回复一条随机消息,而不是分三行。

这是我以前的方法:

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/

相关文章:

regex - 下一个单词的 GREP 跟随包含变量的字符串

javascript - 使用键映射和过滤对象数组

r - 如果字符串包含 x 在 R 中做 y

typescript - 将泛型参数约束为 Typescript 中的联合类型

python - 属性错误 : module 'numpy.core' has no attribu

r - 如何排除 R 中计算均值和标准差的月份

python - Colab 中没有名为 'statsmodels.tsa.arima' 的模块,但

python - 如何将第一列的值分成另外两列

python - UUID 对于 Centos 操作系统上的不同进程保持不变,但在 Windows

javascript - Puppeteer 仅用于 chrome 浏览器吗?