H
H
happyjuic2022-03-26 11:34:56
Python
happyjuic, 2022-03-26 11:34:56

Who can help with discord.py?

I want to post a random phrase from the list, but an error pops up in the console. WHERE IS THE ERROR?!

import discord
from discord.ext import commands
import sqlite3
import random
import time

iq = ["a", "b", "c"] #создаём список со случайными фразами для команды !iq

bot = commands.Bot(command_prefix=('!')) #префикс нашего бота
bot.remove_command( 'help' ) #удаляем базовую команду help

TOKEN = "" #заносим токен бота в переменную

@bot.command()
async def iq(ctx):
  global iq
  await ctx.send('сканирую...')
  time.sleep(1)
  a = random.choice(iq)
  await ctx.send(a)

bot.run(TOKEN)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dr. Bacon, 2022-03-26
@bacon

the mistake is in you, first we learn python, then we write bots

M
MagM1go, 2022-03-28
@MagM1go

at least you can do it like this:

import random

@bot.command()
async def iq(ctx):
    words = ['фраза один', 'фраза два...']
    await ctx.send(random.choice(words))

And yet, leave the text of the error itself, because maybe you just made an incorrect tabulation, which we won’t be able to see here.

M
Maxim Nevzorov, 2022-03-29
@fixator10

You have two variables named the same (function/command and list).

import asyncio
import discord
from discord.ext import commands
import sqlite3
import random

bot = commands.Bot(command_prefix=('!'))
bot.remove_command( 'help' )

TOKEN = ""
IQ_PHRASES = ["a", "b", "c"] 

@bot.command()
async def iq(ctx):
    await ctx.send('сканирую...')
    await asyncio.sleep(1)
    a = random.choice(IQ_PHRASES)
    await ctx.send(a)

bot.run(TOKEN)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question