gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 09:31:11 30 4
gpt4 key购买 nike

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

这是我以前的方法:

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))

关于python - 如何将值合并到 discord.py 中的一条消息中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69023976/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com