I don't understand what the error is.
> Ignoring exception in command weather:
> Traceback (most recent call last):
File "/home/timoha/discord_bot/venv/lib/python3.10/site-packages/discord/enums.py", line 168, in __call__
> return cls._enum_value_map_[value]
> KeyError: <class 'str'>
> During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/timoha/discord_bot/venv/lib/python3.10/site-packages/discord/commands/core.py", line 124, in wrapped
ret = await coro(arg)
File "/home/timoha/discord_bot/venv/lib/python3.10/site-packages/discord/commands/core.py", line 980, in _invoke
await self.callback(ctx, **kwargs)
File "/home/timoha/discord_bot/main.py", line 166, in weather
async with discord.channel.ChannelType(value=str):
File "/home/timoha/discord_bot/venv/lib/python3.10/site-packages/discord/enums.py", line 170, in __call__
> raise ValueError(f"{value!r} is not a valid {cls.__name__}")
> ValueError: <class 'str'> is not a valid ChannelType
>
> The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/timoha/discord_bot/venv/lib/python3.10/site-packages/discord/bot.py", line 1114, in invoke_application_command
await ctx.command.invoke(ctx)
File "/home/timoha/discord_bot/venv/lib/python3.10/site-packages/discord/commands/core.py", line 375, in invoke
await injected(ctx)
File "/home/timoha/discord_bot/venv/lib/python3.10/site-packages/discord/commands/core.py", line 132, in wrapped
> raise ApplicationCommandInvokeError(exc) from exc
> discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: ValueError: <class 'str'> is not a valid ChannelType
Code:
#bot.slash_command(name="weather", description="Погода")
async def weather(ctx, *, city: str):
city_name = city
complete_url = base_url + "appid=" + api_key + "&q=" + city_name
response = requests.get(complete_url)
x = response.json()
channel = ctx.message
if x["cod"] != "404":
async with discord.channel.ChannelType(value=str):
value=str
y = x["главный"]
current_temperature = y["температура"]
current_temperature_celsiuis =str(round(current_temperature - 273.15))
current_pressure = y["давление"]
current_humidity = y["влажность"]
z = x["погода"]
weather_description = z[0]["описание"]
weather_description = z[0]["описание"]
embed = discord.Embed(title=f"Погода в {city_name}",
color=ctx.guild.me.top_role.color,
timestamp=ctx.message.created_at,)
embed.add_field(name="Описание", value=f"**{weather_description}**", inline=False)
embed.add_field(name="Температура(C)", value=f"**{current_temperature_celsiuis}°C**", inline=False)
embed.add_field(name="Влажность(%)", value=f"**{current_humidity}%**", inline=False)
embed.add_field(name="Atmospheric Pressure(hPa)", value=f"**{current_pressure}hPa**", inline=False)
embed.set_thumbnail(url="https://i.ibb.co/CMrsxdX/weather.png")
embed.set_footer(text=f"Запрошенный {ctx.author.name}")
await channel.send(embed=embed)
else:
await channel.send("Город не найден.")
I tried to change a lot of things, but I still can't figure out what the problem is.
There's a few issues with your code - that error is probably just the first one. I've attempted to rewrite what you've provided with some explanation but hopefully it replicates what you're trying to do.
#bot.slash_command(name="weather", description="Погода")
async def weather(ctx, *, city: str):
# as we're doing an API call here - let's defer so the interaction doesn't timeout
await ctx.defer()
# no reason to redefine another variable called 'city_name' equal to 'city' - just use 'city' everywhere
# could also use a f-string for creating the URL here
# complete_url = f"{base_url}appid={api_key}&q={city}"
complete_url = base_url + "appid=" + api_key + "&q=" + city
response = requests.get(complete_url)
json_response = response.json()
if json_response["cod"] == "404":
# if it's 404, let's send the error message and return early
# means we don't have a big nested "if" block
await channel.send("Город не найден.")
return
y = json_response["главный"]
z = json_response["погода"]
current_temperature = y["температура"]
current_temperature_celsiuis =str(round(current_temperature - 273.15))
current_pressure = y["давление"]
current_humidity = y["влажность"]
weather_description = z[0]["описание"]
weather_description = z[0]["описание"]
# create the embed
embed = discord.Embed(
title=f"Погода в {city}",
color=ctx.guild.me.top_role.color,
timestamp=ctx.message.created_at
)
embed.add_field(name="Описание", value=f"**{weather_description}**", inline=False)
embed.add_field(name="Температура(C)", value=f"**{current_temperature_celsiuis}°C**", inline=False)
embed.add_field(name="Влажность(%)", value=f"**{current_humidity}%**", inline=False)
embed.add_field(name="Atmospheric Pressure(hPa)", value=f"**{current_pressure}hPa**", inline=False)
embed.set_thumbnail(url="https://i.ibb.co/CMrsxdX/weather.png")
embed.set_footer(text=f"Запрошенный {ctx.author.name}")
# now let's send our response
# ctx.send will send to the channel that the user used the slash command in
await ctx.send(embed=embed)
The ctx variable docs.
What I changed:
removed creating a variable called city_name that was exactly equal to city - seemed redundant
added ctx.defer() - if our code takes a little while it's good to defer so the interaction doesn't timeout
removed channel = ctx.message. We can get the channel later if we need to (we don't in this case) but this was setting it equal to the message that invoked the application command (which isn't really a message) so we aren't accomplishing anything here anyways
if we get a 404 response; send error message and return. Better to do this than have a big nested if block in my opinion.
I also renamed x to json_response as I prefer descriptive variable names but I gave up on y and z.
got rid of the whatever the async with statement was trying to accomplish
used ctx.send(embed=embed) at the bottom to send your created embed to the channel that the user used the application command in
Hopefully, this is what you want it to do and hopefully you understand what's going on a bit now. It might be worth having a look through some of the examples and documentation to get a better grasp on how it all works.
Another change you could make, is swapping out requests for aiohttp-requests to make non-blocking API calls.
I took advantage of your help, and I am grateful to you in many ways, but I am just starting my way in programming and learning from a real example. So I corrected my code to yours and I was given a new set of errors, which I also can't figure out a little.
gnoring exception in command weather: Traceback (most recent call
last):
File "/home/timoha/discord_bot/venv/lib/python3.10/site-packages/discord/commands/core.py", line 124, in wrapped
ret = await coro(arg)
File "/home/timoha/discord_bot/venv/lib/python3.10/site-packages/discord/commands/core.py", line 980, in _invoke
await self.callback(ctx, **kwargs) File
"/home/timoha/discord_bot/main.py", line 162, in weather
y = json_response["главный"] KeyError: 'главный'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/timoha/discord_bot/venv/lib/python3.10/site-packages/discord/bot.py", line 1114, in invoke_application_command
await ctx.command.invoke(ctx)
File "/home/timoha/discord_bot/venv/lib/python3.10/site-packages/discord/commands/core.py", line 375, in invoke
await injected(ctx)
File "/home/timoha/discord_bot/venv/lib/python3.10/site-packages/discord/commands/core.py", line 132, in wrapped
raise ApplicationCommandInvokeError(exc) from exc
discord.errors.ApplicationCommandInvokeError: Application Command
raised an exception: KeyError: 'главный'
so recently I started coding a chatbot with the Microsoft Bot Framework SDK.
But whatever I deploy to Azure ( even the samples (here: https://github.com/microsoft/BotBuilder-Samples/tree/main/samples/python/57.teams-conversation-bot) throw a lot of access errors. The bot doesn't send a single message. And I really don't know how to fix them or why they appear (edit they appear whenever I message the bot).
More interestingly sometimes the bot even works, but only for a limited amount of time and messaging him like 100 times.
What am I doing wrong? Found nothing on the web that could really help me.
log stream:
2022-06-25T14:14:20.542164844Z Updating certificates in /etc/ssl/certs...
2022-06-25T14:14:33.947672347Z 11 added, 0 removed; done.
2022-06-25T14:14:33.948274356Z Running hooks in /etc/ca-certificates/update.d...
2022-06-25T14:14:33.978379073Z done.
2022-06-25T14:14:34.028116464Z Updated CA certificates
2022-06-25T14:14:39.461850509Z [40m[1m[33mwarn[39m[22m[49m: Middleware[0]
2022-06-25T14:14:39.461884810Z At least one of http20OnlyDestinationHostUrl and http20OnlyListenUrl not provided
Ending Log Tail of existing logs ---
Starting Live Log Stream ---
2022-06-25T14:27:43 No new trace in the past 1 min(s).
2022-06-25T14:28:43 No new trace in the past 2 min(s).
2022-06-25T14:29:43 No new trace in the past 3 min(s).
2022-06-25T14:30:43 No new trace in the past 4 min(s).
2022-06-25T14:31:43 No new trace in the past 5 min(s).
2022-06-25T14:32:43 No new trace in the past 6 min(s).
2022-06-25T14:33:43 No new trace in the past 7 min(s).
2022-06-25T14:34:43 No new trace in the past 8 min(s).
2022-06-25T14:35:43 No new trace in the past 9 min(s).
2022-06-25T14:36:43 No new trace in the past 10 min(s).
2022-06-25T14:37:43 No new trace in the past 11 min(s).
2022-06-25T14:37:54.642576589Z Traceback (most recent call last):
2022-06-25T14:37:54.642618090Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botbuilder/core/integration/aiohttp_channel_service_exception_middleware.py", line 20, in aiohttp_error_middleware
2022-06-25T14:37:54.642637490Z response = await handler(request)
2022-06-25T14:37:54.642642290Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/aiohttp/web_urldispatcher.py", line 927, in _handle
2022-06-25T14:37:54.642646990Z raise self._http_exception
2022-06-25T14:37:54.642651090Z aiohttp.web_exceptions.HTTPNotFound: Not Found
2022-06-25T14:37:54.642655190Z Traceback (most recent call last):
2022-06-25T14:37:54.642659290Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botbuilder/core/integration/aiohttp_channel_service_exception_middleware.py", line 20, in aiohttp_error_middleware
2022-06-25T14:37:54.642663790Z response = await handler(request)
2022-06-25T14:37:54.642667790Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/aiohttp/web_urldispatcher.py", line 927, in _handle
2022-06-25T14:37:54.642672090Z raise self._http_exception
2022-06-25T14:37:54.642676091Z aiohttp.web_exceptions.HTTPNotFound: Not Found
2022-06-25T14:37:54.642680291Z
2022-06-25T14:37:54.642684191Z [on_turn_error] unhandled error: 'access_token'
2022-06-25T14:37:54.642688191Z Traceback (most recent call last):
2022-06-25T14:37:54.642692191Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botbuilder/core/bot_adapter.py", line 128, in run_pipeline
2022-06-25T14:37:54.642696591Z return await self._middleware.receive_activity_with_status(
2022-06-25T14:37:54.642700691Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botbuilder/core/middleware_set.py", line 69, in receive_activity_with_status
2022-06-25T14:37:54.642704991Z return await self.receive_activity_internal(context, callback)
2022-06-25T14:37:54.642709091Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botbuilder/core/middleware_set.py", line 79, in receive_activity_internal
2022-06-25T14:37:54.642713491Z return await callback(context)
2022-06-25T14:37:54.642717491Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botbuilder/core/activity_handler.py", line 70, in on_turn
2022-06-25T14:37:54.642721791Z await self.on_message_activity(turn_context)
2022-06-25T14:37:54.642725791Z File "/tmp/8da56b4c179f50c/bots/teams_conversation_bot.py", line 61, in on_message_activity
2022-06-25T14:37:54.642730091Z await self._send_card(turn_context, False)
2022-06-25T14:37:54.642734091Z File "/tmp/8da56b4c179f50c/bots/teams_conversation_bot.py", line 121, in _send_card
2022-06-25T14:37:54.642738291Z await self._send_welcome_card(turn_context, buttons)
2022-06-25T14:37:54.642743091Z File "/tmp/8da56b4c179f50c/bots/teams_conversation_bot.py", line 135, in _send_welcome_card
2022-06-25T14:37:54.642747392Z await turn_context.send_activity(
2022-06-25T14:37:54.642751292Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botbuilder/core/turn_context.py", line 174, in send_activity
2022-06-25T14:37:54.642759292Z result = await self.send_activities([activity_or_text])
2022-06-25T14:37:54.642763492Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botbuilder/core/turn_context.py", line 226, in send_activities
2022-06-25T14:37:54.642767792Z return await self._emit(self._on_send_activities, output, logic())
2022-06-25T14:37:54.642771892Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botbuilder/core/turn_context.py", line 304, in _emit
2022-06-25T14:37:54.642776192Z return await logic
2022-06-25T14:37:54.642780092Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botbuilder/core/turn_context.py", line 221, in logic
2022-06-25T14:37:54.642784392Z responses = await self.adapter.send_activities(self, output)
2022-06-25T14:37:54.642788392Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botbuilder/core/bot_framework_adapter.py", line 733, in send_activities
2022-06-25T14:37:54.642792792Z raise error
2022-06-25T14:37:54.642796692Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botbuilder/core/bot_framework_adapter.py", line 718, in send_activities
2022-06-25T14:37:54.642800992Z response = await client.conversations.reply_to_activity(
2022-06-25T14:37:54.642805092Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botframework/connector/aio/operations_async/_conversations_operations_async.py", line 524, in reply_to_activity
2022-06-25T14:37:54.642809492Z response = await self._client.async_send(
2022-06-25T14:37:54.642813492Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/msrest/async_client.py", line 115, in async_send
2022-06-25T14:37:54.642817692Z pipeline_response = await self.config.pipeline.run(request, **kwargs)
2022-06-25T14:37:54.642821793Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/msrest/pipeline/async_abc.py", line 159, in run
2022-06-25T14:37:54.642825993Z return await first_node.send(pipeline_request, **kwargs) # type: ignore
2022-06-25T14:37:54.642830093Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/msrest/pipeline/async_abc.py", line 79, in send
2022-06-25T14:37:54.642834293Z response = await self.next.send(request, **kwargs) # type: ignore
2022-06-25T14:37:54.642838393Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/msrest/pipeline/async_requests.py", line 99, in send
2022-06-25T14:37:54.642842893Z self._creds.signed_session(session)
2022-06-25T14:37:54.642848693Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botframework/connector/auth/app_credentials.py", line 98, in signed_session
2022-06-25T14:37:54.642853093Z auth_token = self.get_access_token()
2022-06-25T14:37:54.642857093Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botframework/connector/auth/microsoft_app_credentials.py", line 65, in get_access_token
2022-06-25T14:37:54.642861493Z return auth_token["access_token"]
2022-06-25T14:37:54.642868993Z KeyError: 'access_token'
2022-06-25T14:37:54.642873193Z
2022-06-25T14:37:54.642877193Z [on_turn_error] unhandled error: 'access_token'
2022-06-25T14:37:54.642881193Z Traceback (most recent call last):
2022-06-25T14:37:54.642885193Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botbuilder/core/bot_adapter.py", line 128, in run_pipeline
2022-06-25T14:37:54.642889493Z return await self._middleware.receive_activity_with_status(
2022-06-25T14:37:54.642893694Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botbuilder/core/middleware_set.py", line 69, in receive_activity_with_status
2022-06-25T14:37:54.642897994Z return await self.receive_activity_internal(context, callback)
2022-06-25T14:37:54.642902094Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botbuilder/core/middleware_set.py", line 79, in receive_activity_internal
2022-06-25T14:37:54.642906394Z return await callback(context)
2022-06-25T14:37:54.642910394Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botbuilder/core/activity_handler.py", line 70, in on_turn
2022-06-25T14:37:54.642914594Z await self.on_message_activity(turn_context)
2022-06-25T14:37:54.642918694Z File "/tmp/8da56b4c179f50c/bots/teams_conversation_bot.py", line 61, in on_message_activity
2022-06-25T14:37:54.642922994Z await self._send_card(turn_context, False)
2022-06-25T14:37:54.642926894Z File "/tmp/8da56b4c179f50c/bots/teams_conversation_bot.py", line 121, in _send_card
2022-06-25T14:37:54.642931094Z await self._send_welcome_card(turn_context, buttons)
2022-06-25T14:37:54.642935194Z File "/tmp/8da56b4c179f50c/bots/teams_conversation_bot.py", line 135, in _send_welcome_card
2022-06-25T14:37:54.642939394Z await turn_context.send_activity(
2022-06-25T14:37:54.642943294Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botbuilder/core/turn_context.py", line 174, in send_activity
2022-06-25T14:37:54.642947694Z result = await self.send_activities([activity_or_text])
2022-06-25T14:37:54.642951694Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botbuilder/core/turn_context.py", line 226, in send_activities
2022-06-25T14:37:54.642955994Z return await self._emit(self._on_send_activities, output, logic())
2022-06-25T14:37:54.642960594Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botbuilder/core/turn_context.py", line 304, in _emit
2022-06-25T14:37:54.642964994Z return await logic
2022-06-25T14:37:54.642968895Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botbuilder/core/turn_context.py", line 221, in logic
2022-06-25T14:37:54.642973195Z responses = await self.adapter.send_activities(self, output)
2022-06-25T14:37:54.642977295Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botbuilder/core/bot_framework_adapter.py", line 733, in send_activities
2022-06-25T14:37:54.642981695Z raise error
2022-06-25T14:37:54.642988595Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botbuilder/core/bot_framework_adapter.py", line 718, in send_activities
2022-06-25T14:37:54.642993095Z response = await client.conversations.reply_to_activity(
2022-06-25T14:37:54.642997195Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botframework/connector/aio/operations_async/_conversations_operations_async.py", line 524, in reply_to_activity
2022-06-25T14:37:54.643001595Z response = await self._client.async_send(
2022-06-25T14:37:54.643005595Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/msrest/async_client.py", line 115, in async_send
2022-06-25T14:37:54.643009795Z pipeline_response = await self.config.pipeline.run(request, **kwargs)
2022-06-25T14:37:54.643013895Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/msrest/pipeline/async_abc.py", line 159, in run
2022-06-25T14:37:54.643018095Z return await first_node.send(pipeline_request, **kwargs) # type: ignore
2022-06-25T14:37:54.643022195Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/msrest/pipeline/async_abc.py", line 79, in send
2022-06-25T14:37:54.643026395Z response = await self.next.send(request, **kwargs) # type: ignore
2022-06-25T14:37:54.643030395Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/msrest/pipeline/async_requests.py", line 99, in send
2022-06-25T14:37:54.643034695Z self._creds.signed_session(session)
2022-06-25T14:37:54.643038595Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botframework/connector/auth/app_credentials.py", line 98, in signed_session
2022-06-25T14:37:54.643042896Z auth_token = self.get_access_token()
2022-06-25T14:37:54.643046896Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botframework/connector/auth/microsoft_app_credentials.py", line 65, in get_access_token
2022-06-25T14:37:54.643051296Z return auth_token["access_token"]
2022-06-25T14:37:54.643055496Z KeyError: 'access_token'
2022-06-25T14:38:12.502028598Z
2022-06-25T14:38:12.502066398Z [on_turn_error] unhandled error: 'access_token'
2022-06-25T14:38:12.502072298Z Traceback (most recent call last):
2022-06-25T14:38:12.502076798Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botbuilder/core/bot_adapter.py", line 128, in run_pipeline
2022-06-25T14:38:12.502081298Z return await self._middleware.receive_activity_with_status(
2022-06-25T14:38:12.502085398Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botbuilder/core/middleware_set.py", line 69, in receive_activity_with_status
2022-06-25T14:38:12.502089799Z return await self.receive_activity_internal(context, callback)
2022-06-25T14:38:12.502093899Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botbuilder/core/middleware_set.py", line 79, in receive_activity_internal
2022-06-25T14:38:12.502098099Z return await callback(context)
2022-06-25T14:38:12.502101999Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botbuilder/core/activity_handler.py", line 70, in on_turn
2022-06-25T14:38:12.502118599Z await self.on_message_activity(turn_context)
2022-06-25T14:38:12.502122799Z File "/tmp/8da56b4c179f50c/bots/teams_conversation_bot.py", line 61, in on_message_activity
2022-06-25T14:38:12.502126899Z await self._send_card(turn_context, False)
2022-06-25T14:38:12.502130699Z File "/tmp/8da56b4c179f50c/bots/teams_conversation_bot.py", line 121, in _send_card
2022-06-25T14:38:12.502134799Z await self._send_welcome_card(turn_context, buttons)
2022-06-25T14:38:12.502138799Z File "/tmp/8da56b4c179f50c/bots/teams_conversation_bot.py", line 135, in _send_welcome_card
2022-06-25T14:38:12.502142799Z await turn_context.send_activity(
2022-06-25T14:38:12.502146699Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botbuilder/core/turn_context.py", line 174, in send_activity
2022-06-25T14:38:12.502150799Z result = await self.send_activities([activity_or_text])
2022-06-25T14:38:12.502154699Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botbuilder/core/turn_context.py", line 226, in send_activities
2022-06-25T14:38:12.502158899Z return await self._emit(self._on_send_activities, output, logic())
2022-06-25T14:38:12.502162900Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botbuilder/core/turn_context.py", line 304, in _emit
2022-06-25T14:38:12.502167100Z return await logic
2022-06-25T14:38:12.502170900Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botbuilder/core/turn_context.py", line 221, in logic
2022-06-25T14:38:12.502175000Z responses = await self.adapter.send_activities(self, output)
2022-06-25T14:38:12.502179700Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botbuilder/core/bot_framework_adapter.py", line 733, in send_activities
2022-06-25T14:38:12.502184000Z raise error
2022-06-25T14:38:12.502187900Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botbuilder/core/bot_framework_adapter.py", line 718, in send_activities
2022-06-25T14:38:12.502192100Z response = await client.conversations.reply_to_activity(
2022-06-25T14:38:12.502196000Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botframework/connector/aio/operations_async/_conversations_operations_async.py", line 524, in reply_to_activity
2022-06-25T14:38:12.502200700Z response = await self._client.async_send(
2022-06-25T14:38:12.502204800Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/msrest/async_client.py", line 115, in async_send
2022-06-25T14:38:12.502208900Z pipeline_response = await self.config.pipeline.run(request, **kwargs)
2022-06-25T14:38:12.502213000Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/msrest/pipeline/async_abc.py", line 159, in run
2022-06-25T14:38:12.502217100Z return await first_node.send(pipeline_request, **kwargs) # type: ignore
2022-06-25T14:38:12.502221000Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/msrest/pipeline/async_abc.py", line 79, in send
2022-06-25T14:38:12.502229200Z response = await self.next.send(request, **kwargs) # type: ignore
2022-06-25T14:38:12.502233401Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/msrest/pipeline/async_requests.py", line 99, in send
2022-06-25T14:38:12.502237601Z self._creds.signed_session(session)
2022-06-25T14:38:12.502241501Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botframework/connector/auth/app_credentials.py", line 98, in signed_session
2022-06-25T14:38:12.502245701Z auth_token = self.get_access_token()
2022-06-25T14:38:12.502249601Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botframework/connector/auth/microsoft_app_credentials.py", line 65, in get_access_token
2022-06-25T14:38:12.502253801Z return auth_token["access_token"]
2022-06-25T14:38:12.502257901Z KeyError: 'access_token'
2022-06-25T14:38:12.502261701Z
2022-06-25T14:38:12.502265401Z [on_turn_error] unhandled error: 'access_token'
2022-06-25T14:38:12.502269401Z Traceback (most recent call last):
2022-06-25T14:38:12.502273201Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botbuilder/core/bot_adapter.py", line 128, in run_pipeline
2022-06-25T14:38:12.502277301Z return await self._middleware.receive_activity_with_status(
2022-06-25T14:38:12.502281201Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botbuilder/core/middleware_set.py", line 69, in receive_activity_with_status
2022-06-25T14:38:12.502285801Z return await self.receive_activity_internal(context, callback)
2022-06-25T14:38:12.502289701Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botbuilder/core/middleware_set.py", line 79, in receive_activity_internal
2022-06-25T14:38:12.502293901Z return await callback(context)
2022-06-25T14:38:12.502297701Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botbuilder/core/activity_handler.py", line 70, in on_turn
2022-06-25T14:38:12.502301801Z await self.on_message_activity(turn_context)
2022-06-25T14:38:12.502305602Z File "/tmp/8da56b4c179f50c/bots/teams_conversation_bot.py", line 61, in on_message_activity
2022-06-25T14:38:12.502309702Z await self._send_card(turn_context, False)
2022-06-25T14:38:12.502313602Z File "/tmp/8da56b4c179f50c/bots/teams_conversation_bot.py", line 121, in _send_card
2022-06-25T14:38:12.502317602Z await self._send_welcome_card(turn_context, buttons)
2022-06-25T14:38:12.502321502Z File "/tmp/8da56b4c179f50c/bots/teams_conversation_bot.py", line 135, in _send_welcome_card
2022-06-25T14:38:12.502325602Z await turn_context.send_activity(
2022-06-25T14:38:12.502329402Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botbuilder/core/turn_context.py", line 174, in send_activity
2022-06-25T14:38:12.502333502Z result = await self.send_activities([activity_or_text])
2022-06-25T14:38:12.502337402Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botbuilder/core/turn_context.py", line 226, in send_activities
2022-06-25T14:38:12.502345002Z return await self._emit(self._on_send_activities, output, logic())
2022-06-25T14:38:12.502349302Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botbuilder/core/turn_context.py", line 304, in _emit
2022-06-25T14:38:12.502353402Z return await logic
2022-06-25T14:38:12.502357102Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botbuilder/core/turn_context.py", line 221, in logic
2022-06-25T14:38:12.502361202Z responses = await self.adapter.send_activities(self, output)
2022-06-25T14:38:12.502365102Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botbuilder/core/bot_framework_adapter.py", line 733, in send_activities
2022-06-25T14:38:12.502369302Z raise error
2022-06-25T14:38:12.502373102Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botbuilder/core/bot_framework_adapter.py", line 718, in send_activities
2022-06-25T14:38:12.502377203Z response = await client.conversations.reply_to_activity(
2022-06-25T14:38:12.502381103Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botframework/connector/aio/operations_async/_conversations_operations_async.py", line 524, in reply_to_activity
2022-06-25T14:38:12.502385803Z response = await self._client.async_send(
2022-06-25T14:38:12.502390003Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/msrest/async_client.py", line 115, in async_send
2022-06-25T14:38:12.502394203Z pipeline_response = await self.config.pipeline.run(request, **kwargs)
2022-06-25T14:38:12.502398103Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/msrest/pipeline/async_abc.py", line 159, in run
2022-06-25T14:38:12.502402203Z return await first_node.send(pipeline_request, **kwargs) # type: ignore
2022-06-25T14:38:12.502406103Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/msrest/pipeline/async_abc.py", line 79, in send
2022-06-25T14:38:12.502410203Z response = await self.next.send(request, **kwargs) # type: ignore
2022-06-25T14:38:12.502414003Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/msrest/pipeline/async_requests.py", line 99, in send
2022-06-25T14:38:12.502418103Z self._creds.signed_session(session)
2022-06-25T14:38:12.502421903Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botframework/connector/auth/app_credentials.py", line 98, in signed_session
2022-06-25T14:38:12.502426103Z auth_token = self.get_access_token()
2022-06-25T14:38:12.502429903Z File "/tmp/8da56b4c179f50c/antenv/lib/python3.8/site-packages/botframework/connector/auth/microsoft_app_credentials.py", line 65, in get_access_token
2022-06-25T14:38:12.502434103Z return auth_token["access_token"]
2022-06-25T14:38:12.502438103Z KeyError: 'access_token'
I'm trying to get the 4-digit tag of the person who used the command !hours, but discord won't recognize user.tag
import discord
from discord import message
from discord.ext import commands
client = commands.Bot(command_prefix = '!')
##########HOURS##########
chung_victor = [21, 10]
##########HOURS##########
# chung_victor
if usertag == 5308:
h = chung_victor[0]
m = chung_victor[1]
await ctx.send(f'> You currently have {h} hours and {m} minutes!')
And when I use !hours, I get the error message
Ignoring exception in command hours:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "main.py", line 36, in hours
usertag = message.user.tag
AttributeError: module 'discord.message' has no attribute 'user'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: module 'discord.message' has no attribute 'user'
Well, as you see to get user name you need to use it as user.name and same goes for the discriminator user.discriminator. You can refer to the code below :
#bot.command()
async def test(ctx, member : discord.Member, *,reason = None) :
user = member.discriminator
await ctx.send(f" User Tag is : {user} ")
In the example above, I set a command test and user must tag someone after a command like:
!test #Victor Chung and ! is a command_prefix.
Thank You :)
There is a great library that I want to use from a larger project that I'm working on that uses "standard asyncio". Some of the functionality of the library calls curio.spawn which results in an error when called from "standard asyncio". Is there a way to get this to work?
Example code that reproduces the error:
import curio
import asyncio
async def curio_method():
await curio.sleep(1)
async def asyncio_method():
task = await curio.spawn(curio_method())
await task
asyncio.run(asyncio_method())
Result:
Traceback (most recent call last):
File "/tmp/curio_test.py", line 12, in <module>
asyncio.run(asyncio_method())
File "/usr/lib/python3.9/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
return future.result()
File "/tmp/curio_test.py", line 8, in asyncio_method
task = await curio.spawn(curio_method())
File "/home/garyvdm/dev/image_builder/bpmagent/ve/lib/python3.9/site-packages/curio/task.py", line 613, in spawn
task = await _spawn(coro)
File "/home/garyvdm/dev/image_builder/bpmagent/ve/lib/python3.9/site-packages/curio/traps.py", line 83, in _spawn
return await _kernel_trap('trap_spawn', coro)
File "/home/garyvdm/dev/image_builder/bpmagent/ve/lib/python3.9/site-packages/curio/traps.py", line 32, in _kernel_trap
result = yield request
RuntimeError: Task got bad yield: ('trap_spawn', <coroutine object curio_method at 0x7fc1b62eeec0>)
sys:1: RuntimeWarning: coroutine 'curio_method' was never awaited
Instead of asyncio.run, you can use curio.run.
But, if you need to use asyncio.run, you can put your curio.run inside your asyncio.run logic. Anyway, I think that is not the idea.
When I try to get values for a list of keys using asyncio_redis or aioredis, I am getting the following error. I know it is about something python socket, but unable to resolve the error. I attached both the code and error log with this issue. Here keys are a list of large byte arrays. get_params_redis is called by multiple processes. Any help would be appreciated, thanks!
async def multi_get_key_redis(keys):
redis = await aioredis.create_redis_pool(
'redis://localhost')
result =[]
for key in keys:
result.append(await redis.get(key))
# assert result == await asyncio.gather(*keys)
# return result
redis.close()
await redis.wait_closed()
print(result)
return result
def get_params_redis(shapes):
i = -1
params=[]
keys = []
for s in range(len(shapes)):
keys.append(s)
values = asyncio.get_event_loop().run_until_complete(multi_get_key_redis(keys))
for shape in shapes:
i = i + 1
param_np = pc._loads(values[i]).reshape(shape)
param_tensor = torch.nn.Parameter(torch.from_numpy(param_np))
params.append(param_tensor)
return params
Error Log:
Process Process-1:
Traceback (most recent call last):
File "/usr/local/Cellar/python/3.6.4_4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/multiprocessing/process.py", line 258, in _bootstrap
self.run()
File "/usr/local/Cellar/python/3.6.4_4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/multiprocessing/process.py", line 93, in run
self._target(*self._args, **self._kwargs)
File "/Users/srujithpoondla/largescaleml_project/train_redis.py", line 33, in train_redis
train_redis_epoch(epoch, args, model, train_loader, optimizer,shapes_len, loop)
File "/Users/srujithpoondla/largescaleml_project/train_redis.py", line 43, in train_redis_epoch
params = get_params_redis(shapes_len,loop)
File "/Users/srujithpoondla/largescaleml_project/common_functions.py", line 76, in get_params_redis
params = loop.run_until_complete(multi_get_key_redis(keys))
File "/usr/local/Cellar/python/3.6.4_4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/base_events.py", line 454, in run_until_complete
self.run_forever()
File "/usr/local/Cellar/python/3.6.4_4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/base_events.py", line 421, in run_forever
self._run_once()
File "/usr/local/Cellar/python/3.6.4_4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/base_events.py", line 1395, in _run_once
event_list = self._selector.select(timeout)
File "/usr/local/Cellar/python/3.6.4_4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/selectors.py", line 577, in select
kev_list = self._kqueue.control(None, max_ev, timeout)
OSError: [Errno 9] Bad file descriptor