2021年3月28日星期日

Trying to make a discord bot that sends a random message at a random time, but I keep getting this error

Here is my code:

import random  import discord  import asyncio    from discord.ext import commands    bot = commands.Bot(command_prefix='!')    msg = ['msg1','msg2','msg3']    @bot.command()  async def test(message):    while True:      chance = random.randint(1,4)      print(chance)      if chance == 1:        msj = random.choice(msg)        await message.send(msj)      time = random.randint(60,3600)      print(time)      await asyncio.sleep(time)  bot.loop.create_task(test("!test"))  

And there is my error :

await message.send(msj)  AttributeError: 'str' object has no attribute 'send'  

I tried to do this thing using bot.event, using await bot.send(channel, msj), but I get a similar error:

await bot.send(channel, msj)  AttributeError: 'Bot' object has no attribute 'send'  

Any ideas? Thanks

https://stackoverflow.com/questions/66842477/trying-to-make-a-discord-bot-that-sends-a-random-message-at-a-random-time-but-i March 28, 2021 at 10:27PM

没有评论:

发表评论