0
votes

I am trying to make a discord bot to make random encounters for a dnd, Right now I have the code

import discord
import os
import random
import asyncio
client = discord.Client()

@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))

@client.event
async def on_message(message):
    if message.author == client.user:
        return
    
    if message.content.startswith('$desert'):

        DesertList = ['charmander', 'charmeleon', 'charizard']

        Desert = random.choice(DesertList)
        await message.channel.send(Desert)

client.run("just trust me its the right ID")

What I am trying to do is send Desert (defined Desert = random.choice(DesertList)) but the bot doesn't send anything. I have tested if Desert has a value in the console in visual studio and it returns a random name. I was basing it off of something that works in discord where I type $hello in a channel and it replies Hello!

@client.event
async def on_message(message):
    if message.author == client.user:
        return

    if message.content.startswith('$hello'):
        await message.channel.send('Hello!')
1

1 Answers

0
votes

K so I finished it, it all works. The final code is looking like

import discord
import os
import random
import asyncio
client = discord.Client()

DesertList1 = 'none'
DesertList2 = 'none'

def printdesert():
    print(DesertList1)

def randomizedesert():
    global DesertList1
    global DesertList2
    DesertList2 = ['charmander', 'charmeleon', 'charizard']
    DesertList1 = random.choice(DesertList2)


@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))

@client.event
async def on_message(message):
    if message.author == client.user:
        return
    
    if message.content.startswith('$desert'):
        global DesertList1
        randomizedesert()
        printdesert()
        message.channel.send("bruh")
        await message.channel.send(DesertList1)

client.run(":)")

Simplifying it is a necessity but one for a later date