开发者

Discord Bot : 'Message' object has no attribute 'channell'

开发者 https://www.devze.com 2022-12-07 21:32 出处:网络
I have created a Discord bot with a Python script. This is a simple Discord bot where users can interact with it via specific messages. For example: when the user types "roll", the bot will

I have created a Discord bot with a Python script. This is a simple Discord bot where users can interact with it via specific messages. For example: when the user types "roll", the bot will roll the dice and give a random number.

main.py
import bot

if __name__ == '__main__':
    bot.run_discord_bot()

bot.py
import discord
import responses

async def send_message(message, user_message, is_private):
开发者_如何学C    try: 
        response =  responses.get_response(user_message) # Need to be implemented
        await message.author.send(response) if is_private else await message.channell.send(response)
        
    except Exception as e:
        print(e)
        
def run_discord_bot():
    TOKEN = ''
    intents = discord.Intents.default()
    intents.message_content = True
    client = discord.Client(intents=intents)
    
    @client.event
    async def on_ready():
        print(f'{client.user} is now running!')
        
    @client.event
    async def on_message(message):
        if message.author == client.user:
            return 
        
        username = str(message.author)
        user_message = str(message.content)
        channel = str(message.channel)
        
        print(f'{username} said: "{user_message}" ({channel})')
        
        if user_message[0] == '?':
            user_message = user_message[1:] 
            await send_message(message, user_message, is_private=True)
        else:
            await send_message(message, user_message, is_private=False)
            
    client.run(TOKEN)

responses.py
import random

def get_response(message: str) -> str:
    p_message = message.lower() 
    
    if p_message == 'hello':
        return 'Hey there!'
    
    if p_message == 'roll':
        return str(random.randint(1,9))
    
    if p_message == '!help':
        return '`This is a help message that you can asked for.`'
    
    return 'I didn\'t understand what you wrote. Try typing "!help".'

When the user input a hello, the bot did not respond and the code terminal print out an error message: 'Message' object has no attribute 'channell' What happen? and how to fix it?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号