Answer the question
In order to leave comments, you need to log in
What to do with this error " Ignoring exception in on_message Traceback (most recent call last): "?
I wrote a discord bot, this chat bot on command will send the cost of the bitcoin cryptocurrency (Bitcoin).
When run, it gives an error:
[command]: btcprice
Ignoring exception in on_message
Traceback (most recent call last):
Code itself:
import discord
import asyncio
import requests
import nest_asyncio
nest_asyncio.apply()
DISCORD_BOT_TOKEN = 'секрет"
BTC_PRICE_URL_coinmarketcap = 'https://api.coinmarketcap.com/v1/ticker/bitcoin/?c...'
client = discord.Client()
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
@client.event
async def on_message(message):
if message.content.startswith('!btcprice'):
print('[command]: btcprice ')
btc_price_usd, btc_price_rub = get_btc_price()
await client.send_message(message.channel, 'USD: ' + str(btc_price_usd) + ' | RUB: ' + str(btc_price_rub))
def get_btc_price():
r = requests.get(BTC_PRICE_URL_coinmarketcap)
response_json = r.json()
usd_price = response_json[0]['price_usd']
rub_rpice = response_json[0]['price_rub']
return usd_price, rub_rpice
client.run(DISCORD_BOT_TOKEN)
Answer the question
In order to leave comments, you need to log in
Not
await client.send_message(message.channel, 'USD: ' + str(btc_price_usd) + ' | RUB: ' + str(btc_price_rub))
await channel.send()
channel = message.channel
await channel.send("Куприв")
async def btcprice(ctx):
channel = ctx.channel
print('[command]: btcprice ')
btc_price_usd, btc_price_rub = get_btc_price()
await channel.send('USD: ' + str(btc_price_usd) + ' | RUB: ' + str(btc_price_rub))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question