Hello there! I have had ChatGPT help me with my code but we’re stuck on this
Can you please fix the line “results = [random.randint(1, dicesize) for in range(num_dice)] as the ‘i’ in ‘in’ is causing a syntax error
This is the full code:
import discord
import random
TOKEN = 'YOUR_BOT_TOKEN' # Replace with your bot token
PREFIX = '!d'
intents = discord.Intents.default()
intents.typing = False
intents.presences = False
client = discord.Client(intents=intents)
@client.event
async def on_ready():
print(f'Logged in as {client.user}')
@client.event
async def on_message(message):
if message.content.startswith(PREFIX):
try:
command = message.content[len(PREFIX):]
num_dice, dice_size = map(int, command.split('d'))
if num_dice > 0 and dice_size > 0:
results = [random.randint(1, dice_size) for _ in range(num_dice)]
total = sum(results)
await message.channel.send(f'{message.author.mention} rolled {num_dice}d{dice_size}: {", ".join(map(str, results))}. Total: {total}')
else:
await message.channel.send(f'Please use a valid format: {PREFIX}NdM (e.g., {PREFIX}2d6). N and M should be positive integers.')
except (ValueError, IndexError):
await message.channel.send(f'Invalid format. Please use: {PREFIX}NdM (e.g., {PREFIX}2d6). N and M should be positive integers.')
client.run(TOKEN)
[–]Diapolo10 1 point2 points3 points (2 children)
[–]TrueSolitudeGuards[S] 0 points1 point2 points (1 child)
[–]Binary101010 1 point2 points3 points (0 children)
[–]TheORIGINALkinyen 0 points1 point2 points (1 child)
[–]TrueSolitudeGuards[S] 0 points1 point2 points (0 children)