Attempting to check for keys.
@@ -49,17 +49,15 @@ class InteractionContext:
self._token = _json["token"]
self._type = _json["type"] # Factor to check if its a slash command vs menus
self.message = None
- self._message_menu_id = (
- None if self._type != 2 else _json["data"]["resolved"]["messages"]
- ) # Should be set later.
- self._author_menus_id = None if self._type != 1 else _json["data"]["resolved"]["members"]
+ self.data = _json["data"]
+ self._message_menu_id = self.data["resolved"]["messages"] or None # Should be set later.
+ self._author_menus_id = self.data["resolved"]["members"] or None
self.interaction_id = _json["id"]
self._http = _http
self.bot = _discord
self._logger = logger
self.deferred = False
self.responded = False
- self.data = _json["data"]
self.values = _json["data"]["values"] if "values" in _json["data"] else None
self._deferred_hidden = False # To check if the patch to the deferred response matches
self.guild_id = int(_json["guild_id"]) if "guild_id" in _json.keys() else None
@@ -79,6 +77,8 @@ class InteractionContext:
_json["member"]["user"]["id"] if "member" in _json.keys() else _json["user"]["id"]
)
self.channel_id = int(_json["channel_id"])
+ self.message_menus = None
+ try:
if self._message_menu_id:
self.message_menus = model.SlashMessage(
state=self.bot._connection,
@@ -88,7 +88,9 @@ class InteractionContext:
interaction_token=self._token,
)
else:
- self.message_menus = None
+ raise KeyError
+ except KeyError as err:
+ return err
if self.guild:
self.author = discord.Member(
data=_json["member"], state=self.bot._connection, guild=self.guild
@@ -291,7 +293,7 @@ class InteractionContext:
for file in files:
file.close()
if not hidden:
- if not self.message_menus:
+ if self.message_menus:
smsg = self.message_menus
else:
smsg = model.SlashMessage(
