Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
253 views
in Technique[技术] by (71.8m points)

I am trying to make a discord bot that will sometimes give a random response python

I am not that good at programming and can not get this to work I am getting the error "'Client' object has no attribute 'send_message'" I don't know how to fix it but StackOverflow is making me type more stuff I do have discord.py installed I have look at lots of pages on this I don't relly know what to put hear

import discord
from discord.ext import commands
import random

client = discord.Client()

@client.event
async def on_ready():
    print('bot is ready')

@client.event
async def on_message(message):
    i = random.randint(0,30)
    elif i == 4:
        await client.send_message(message.channel, 'msg')
    elif i == 3:
        await client.send_message(message.channel, 'msg')
    elif i == 2:
        await client.send_message(message.channel, 'msg')
    elif i == 1:
        await client.send_message(message.channel, 'msg')
    elif i == 6:
        await client.send_message(message.channel, 'msg')
    elif i == 7:
        await client.send_message(message.channel, 'msg')
    elif i == 8:
        await client.send_message(message.channel, 'msg')
    elif i == 9:
        await client.send_message(message.channel, 'msg')
    elif i == 10:
        await client.send_message(message.channel, 'msg')
    elif i == 11:
        await client.send_message(message.channel, 'msg')
    elif i == 12:
        await client.send_message(message.channel, 'msg')
    elif i == 14:
        await client.send_message(message.channel, 'msg')
    elif i == 15:
        await client.send_message(message.channel, 'msg')
    elif i == 16:
        await client.send_message(message.channel, 'msg')
    elif i == 17:
        await client.send_message(message.channel, 'msg')
    elif i == 18:
        await client.send_message(message.channel, 'msg')
    elif i == 19:
        await client.send_message(message.channel, 'msg')
    elif i == 20:
        await client.send_message(message.channel, 'msg')
    elif i == 21:
        await client.send_message(message.channel, 'msg')
    elif i == 22:
        await client.send_message(message.channel, 'msg')
    elif i == 24:
        await client.send_message(message.channel, 'msg')
    elif i == 25:
        await client.send_message(message.channel, 'msg')
    elif i == 26:
        await client.send_message('msg')

    await client.process_commands(message)

client.run('TOKEN')
question from:https://stackoverflow.com/questions/65599325/i-am-trying-to-make-a-discord-bot-that-will-sometimes-give-a-random-response-pyt

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use await message.channel.send instead of await client.send_message


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...