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

taz*_*zan 2 python merge bots discord discord.py

我希望我的机器人能够说出一条消息,提及一个用户,然后用一条随机消息响应,所有这些都在同一行中,而不是在 3 个单独的行中。

这是我以前的方法:

if msg.startswith('respond')
    await message.channel.send('alright then,')
    await message.channel.send(message.author.mention)
    await message.channel.send(random.choice(responses))
Run Code Online (Sandbox Code Playgroud)

但是,这使它们都出现在同一行中,但我不知道如何将它们合并为一条单行。这是我多次失败的尝试之一:

if msg.startswith('respond'):
    await message.channel.send ('alright then, <message.author.mention> <random.choice(responses)>')
Run Code Online (Sandbox Code Playgroud)

(请不要取笑我的业余编码技巧lmao)

Inz*_*Lee 6

假设你使用的是 python3+,你可以做 f-strings

if msg.startswith('respond'):
    await message.channel.send(f'alright then, {message.author.mention} {random.choice(responses)}')
Run Code Online (Sandbox Code Playgroud)

还有其他替代方法,例如格式字符串

if msg.startswith('respond'):
    await message.channel.send('alright then, {} {}'.format(message.author.mention, random.choice(responses))
Run Code Online (Sandbox Code Playgroud)

连接方法如

if msg.startswith('respond'):
    await message.channel.send('alright then, ' + message.author.mention + ' ' + random.choice(responses))
Run Code Online (Sandbox Code Playgroud)