Бот Discord.py не будет печатать переменную SIMPLE в чате - PullRequest
0 голосов
/ 29 мая 2018

Я хочу, чтобы бот сказал Snacktoshis: 5, но он не напечатает переменную в чате.

Вот мой код:

from discord import *
from discord.ext import *
from discord.ext.commands import Bot
from discord.ext.commands import *
import random
import asyncio
from discord import Game
from discord.ext.commands import Bot
import aiohttp
import discord
import requests
import time

BOT_PREFIX = ("?", "!")
client = Bot(command_prefix=BOT_PREFIX)

TOKEN ="3812236138921603126360103210983inserttoken21831382ufsfuadha"



@client.command()
async def bal():
    snack = 0
    await client.say("Snacktoshis:",snack)


client.run(TOKEN)

Мое сообщение об ошибке:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/discord/ext/commands/bot.py", line 846, in process_commands
    yield from command.invoke(ctx)
  File "/usr/local/lib/python3.6/site-packages/discord/ext/commands/core.py", line 374, in invoke
    yield from injected(*ctx.args, **ctx.kwargs)
  File "/usr/local/lib/python3.6/site-packages/discord/ext/commands/core.py", line 54, in wrapped
    raise CommandInvokeError(e) from e
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: send_message() takes from 2 to 3 positional arguments but 4 were given

Я знаю, что у меня много неиспользуемых модулей.

Ответы [ 2 ]

0 голосов
/ 29 мая 2018

С help('discord.ext.commands.Bot.say'):

discord.ext.commands.Bot.say = say(self, *args, **kwargs)

Вспомогательная функция, эквивалентная выполнению

    self.send_message(message.channel, *args, **kwargs)

Итак, четыре аргумента, которые отправляются в send_message от вашего client.say вызова client, message.channel, "Snacktoshis:" и snack.Вы хотите, чтобы отправляемое сообщение представляло собой одну строку вместо двух отдельных аргументов.

await client.say("Snacktoshis: " + snack)

или

await client.say("Snacktoshis: {}".format(snack))
0 голосов
/ 29 мая 2018

Я предполагаю, что вы имеете в виду что-то вроде этого:

@bot.command()
async def bal():
  snack = 0
  await bot.say("Snacktoshis: %d" %snack)

Где переменная должна быть частью сообщения, а не отдельным аргументом для вызова метода.

...