Форум сайта python.su
Привет.
В программировании я недавно, так что прошу не кидаться тапками.
Пытаюсь сделать бота для сервера дискорд, который будет будет выводить счет BTC в рублях и долларах.
При проверке (F5) все нормально, но про вводе команды в чате сервера бот ничего не происходит, а бот начинает материться.
Ignoring exception in on_message
Traceback (most recent call last):
File “E:\Python\lib\site-packages\discord\client.py”, line 307, in _run_event
yield from getattr(self, event)(*args, **kwargs)
File “C:\Users\123\Desktop\BOT\erid_bot(empty).py”, line 23, in on_message
if message.context.startswith('btc'):
NameError: name ‘message’ is not defined
Вот сама 23я строчка:
if message.context.startswith('btc'):
import discord import asyncio import requests from discord.ext.commands import Bot from discord.ext import commands Client = discord.Client() bot_prefix= "//" client = commands.Bot(command_prefix=bot_prefix) @client.event async def on_ready(): print("Bot Online!") print(client.user.name) print(client.user.id) print('------') await client.change_presence(game=discord.Game(name='Use //help')) BTC_PRICE_URL_coinmarketcap = ('https://api.coinmarketcap.com/v1/ticker/bitcoin/?convert=RUB') @client.event async def on_message(pass_context=True): if message.context.startswith('btc'): print('[command]: btc ') btc_price_usd, bct_price_rub = get_btc_price() await client.send.message(message.chanel, 'USD: ' + str(btc_price_usd) + ' | rub: ' + str(btc_price_rub)) def get_btc_price(): response = request.get(BTC_PRICE_URL_coinmaketcap) response_json = r.json() usd_price = response_json[0]['price_usd'] rub_price = responce_json[0]['price_rub'] return usd_price, rub_price client.run('XXX')
Офлайн