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

问题描述 投票:0回答:1

我不知道如何表达这个问题,但是我试图将所有信息从机器人中收集到一个响应中。

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)

例如,如果用户键入“; 2d6”,我希望机器人分别在第一卷和第二卷中键入“ 2,6”,然后让机器人将两个数字加在一起“ 8”线。这是不垃圾聊天的生活品质。我该怎么办?我要寻找的最终结果将是这样的“您滚动xy总计z。”

python-3.x discord.py dice
1个回答
0
投票

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

还请注意,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)
© www.soinside.com 2019 - 2024. All rights reserved.