我如何将一个整数附加到我的机器人的一行中?

How would I append an integer to a single line from my bot?

我不知道如何表达这个问题,但我正在尝试将滚动中的所有信息放入我的机器人的一个响应中。

import discord
import random

DND_1d6 = [1, 2, 3, 4, 5, 6]

@client.event
async def on_message(message):
    if message.content.startswith(";roll 1d6"):
        response = random.choice(DND_1d6)
        await message.channel.send(response)

    if message.content.startswith(";roll 2d6"):
        response = random.choice(DND_1d6), random.choice(DND_1d6)
        response_added = random.choice(DND_1d6) + random.choice(DND_1d6)
# how would i use these two variables together in one line?
        await message.channel.send()

client.run(client_id)

例如,如果用户输入“;roll 2d6”,我想让机器人分别输入第一卷和第二卷“2、6”,然后让机器人将这两个数字加在一起“8”一切都在一条很好的线上。这只是生活质量的事情,不要在聊天中发送垃圾邮件。我该怎么办?我正在寻找的最终结果是这样的 "You rolled x and y for a total of z."

您可以使用获得的结果构建一个字符串并将其发送到频道。

另请注意,response = random.choice(DND_1d6), random.choice(DND_1d6) 创建了包含两个卷的 tuple,例如 (2,6)。您不需要像在 response = random.choice(DND_1d6), random.choice(DND_1d6) 中那样再次掷骰子,因为这些会给您不同的数字(它们与之前的掷骰子无关)。

import discord
import random

DND_1d6 = [1, 2, 3, 4, 5, 6]

@client.event
async def on_message(message):
    if message.content.startswith(";roll 1d6"):
        response = random.choice(DND_1d6)
        await message.channel.send(response)

    if message.content.startswith(";roll 2d6"):
        response = random.choice(DND_1d6), random.choice(DND_1d6)
        response_str = 'You rolled {0} and {1} for a total of {2}'.format(response[0], response[1], sum(response))
        await message.channel.send(response_str )

client.run(client_id)