Discord Bot:我将如何进行这项工作?
Discord Bot: How would I make this work?
我目前有一个 python discord bot 脚本,它可以获取某个硬币价格的 API,但是,每当我尝试将其放入 'client.change_presence' 时,它都会给出我 "must be a str, not a list" 错误。
我尝试将其转换为字符串,正如您将在我的源代码中看到的那样,但这也不起作用,得出:"TypeError: Can Only Join An Iterable"
import requests
import discord
import asyncio
url = 'https://cryptohub.online/api/market/ticker/PLSR/'
response = requests.get(url)
data = response.json()['BTC_PLSR']
client = discord.Client()
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
list = data['last']
price = print('PLSR Price:', data['last'])
string = ''.join(list)
await client.change_presence(game=discord.Game(name="PLSR Price: " + string))
@client.event
async def on_message(message):
if message.content.startswith('!test'):
counter = 0
tmp = await client.send_message(message.channel, 'Calculating messages...')
async for log in client.logs_from(message.channel, limit=100):
if log.author == message.author:
counter += 1
await client.edit_message(tmp, 'You have {} messages.'.format(counter))
elif message.content.startswith('!sleep'):
await asyncio.sleep(5)
await client.send_message(message.channel, 'Done sleeping')
client.run('Removed Token for Security Reasons')
我怎样才能完成这项工作?谢谢! (Python 3.6.4)
data['last']
是一个浮点数,而不是一些可迭代的字符串。只需使用 str(data['last'])
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
last = str(data['last'])
price = print('PLSR Price:', last)
await client.change_presence(game=discord.Game(name="PLSR Price: " + last))
我目前有一个 python discord bot 脚本,它可以获取某个硬币价格的 API,但是,每当我尝试将其放入 'client.change_presence' 时,它都会给出我 "must be a str, not a list" 错误。
我尝试将其转换为字符串,正如您将在我的源代码中看到的那样,但这也不起作用,得出:"TypeError: Can Only Join An Iterable"
import requests
import discord
import asyncio
url = 'https://cryptohub.online/api/market/ticker/PLSR/'
response = requests.get(url)
data = response.json()['BTC_PLSR']
client = discord.Client()
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
list = data['last']
price = print('PLSR Price:', data['last'])
string = ''.join(list)
await client.change_presence(game=discord.Game(name="PLSR Price: " + string))
@client.event
async def on_message(message):
if message.content.startswith('!test'):
counter = 0
tmp = await client.send_message(message.channel, 'Calculating messages...')
async for log in client.logs_from(message.channel, limit=100):
if log.author == message.author:
counter += 1
await client.edit_message(tmp, 'You have {} messages.'.format(counter))
elif message.content.startswith('!sleep'):
await asyncio.sleep(5)
await client.send_message(message.channel, 'Done sleeping')
client.run('Removed Token for Security Reasons')
我怎样才能完成这项工作?谢谢! (Python 3.6.4)
data['last']
是一个浮点数,而不是一些可迭代的字符串。只需使用 str(data['last'])
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
last = str(data['last'])
price = print('PLSR Price:', last)
await client.change_presence(game=discord.Game(name="PLSR Price: " + last))