这是我的代码:
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"))
还有我的错误:
await message.send(msj)
AttributeError: 'str' object has no attribute 'send'
我尝试使用 bot.event,使用 await bot.send(channel, msj)
来做这件事,但我得到了类似的错误:
await bot.send(channel, msj)
AttributeError: 'Bot' object has no attribute 'send'
有什么想法吗?谢谢
答案 0 :(得分:0)
尝试添加 ctx 而不是消息,然后执行:await ctx.message.channel.send(msg)