Discord Implementation
See original GitHub issueWhen I try to run a command to use scrython in my discord bot, it creates an error when I start using the scrython library. My code is as follows:
import discord
import BotUtils
from discord.ext import commands
import scrython
bot = commands.Bot(description="FetchBot", command_prefix="!")
@bot.command()
async def getcard(name):
getCard = str(name)
card = scrython.cards.Named(fuzzy=getCard)
if card.type_line() == 'Creature':
PT = "({}/{})".format(card.power(), card.toughness())
else:
PT = ""
if card.cmc() == 0:
mana_cost = ""
else:
mana_cost = card.mana_cost()
string = """
{cardname} {mana_cost}
{type_line} {set_code} {rarity}
{oracle_text}{power_toughness}
""".format(
cardname=card.name(),
mana_cost=mana_cost,
type_line=card.type_line(),
set_code=card.set_code().upper(),
rarity=card.rarity(),
oracle_text=card.oracle_text(),
power_toughness=PT
)
print(string)
bot.run(BotUtils.AUTH_TOKEN)
When I run the !getcard command using any card name (I’ve tested with Opt, Moat, Hijack, Entomb, Naturalize, Progenitus, Mindslaver, and Glimmervoid) I get this error:
Ignoring exception in command getcard
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\ext\commands\core.py", line 50, in wrapped
ret = yield from coro(*args, **kwargs)
File "C:/Users/User/PycharmProjects/bot1.1/botBase.py", line 142 in getcard
card = scrython.cards.Named(fuzzy=getCard)
File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\site-packages\scrython\cards\named.py", line 18, in __init__
super(Named, self).__init__(self.url)
File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\site-packages\scrython\cards\cards_object.py", line 25, in __init__
loop.run_until_complete(main(loop))
File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\asyncio\base_events.py", line 454, in run_until_complete
self.run_forever()
File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\asyncio\base_events.py", line 408, in run_forever
raise RuntimeError('This event loop is already running')
RuntimeError: This event loop is already running
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\ext\commands\bot.py", line 846, in process_commands
yield from command.invoke(ctx)
File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\ext\commands\core.py", line 374, in invoke
yield from injected(*ctx.args, **ctx.kwargs)
File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\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: RuntimeError: This event loop is already running
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Open Source Projects - Discord
SortedSet is a fast and efficient data structure, implemented in a Native Implemented Function in Rust, that provides certain guarantees and functionality.
Read more >Discord - Wikipedia
Discord is a VoIP and instant messaging social platform. Users have the ability to ... Discord has implemented a trust and safety team...
Read more >How PlayStation Could Successfully Implement Discord ...
PlayStation's upcoming integration with Discord in 2022 will open up many more opportunities for gamers to turn gaming into a social ...
Read more >How to Make a Discord Bot in Python - Real Python
Creating a Discord Connection. The first step in implementing your bot user is to create a connection to Discord. With discord.py , you...
Read more >How To Build a Discord Bot with Node.js - DigitalOcean
Learning how to create Discord bots allows you to implement many possibilities, which thousands of people could interact with every day.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Sorry to necro this in 2020
A workaround for this is to use
nest_asyncio
, e.g. these imports should work:Hi all! This also seems to take place with the latest version on Jupyter Notebooks.
I’ll try to look into it in that scenario. I’d really love to get this working for my data explorations 😁