Repository: Pycord-Development/pycord

Issue:
Can't Start A Guild Scheduled Event Immediately After Its Creation
### Summary

[Someone in help channels had a problem with this](https://discord.com/channels/881207955029110855/881309521610412082/928846208389246976), so when I tried it out, I had the same error! I have no idea on how to fix this so here I am.

### Reproduction Steps

1. Make sure your bot has the `Manage Events` permission
2. Run the Minimal Reproducible Code
3. Join a VC
4. Run the slash command (`/start`)

### Minimal Reproducible Code

```python
@bot.slash_command()
async def start(ctx: discord.ApplicationContext):
    scheduled_event: discord.ScheduledEvent = await ctx.guild.create_scheduled_event(
        name='test', 
        start_time=discord.utils.utcnow()+datetime.timedelta(0, 30),
        location=ctx.author.voice.channel
    )
    await scheduled_event.start()
    await ctx.respond('created and started event')
```


### Expected Results

1. The bot would create the guild-scheduled event
2. Immediately start that created event

### Actual Results

Only number 1 happens.
When trying to start that created event, this exception would pop up:
```
Traceback (most recent call last):
  File "pycord/discord/commands/commands.py", line 97, in wrapped
    ret = await coro(arg)
  File "pycord/discord/commands/commands.py", line 629, in _invoke
    await self.callback(ctx, **kwargs)
  File "test.py", line 17, in start
    await scheduled_event.start()
  File "pycord/discord/scheduled_events.py", line 364, in start
    return await self.edit(status=ScheduledEventStatus.active, reason=reason)
  File "pycord/discord/scheduled_events.py", line 321, in edit
    data = await self._state.http.edit_scheduled_event(self.guild.id, self.id, **payload, reason=reason)
  File "pycord/discord/http.py", line 339, in request
    raise HTTPException(response, data)
discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In channel_id: Cannot update the channel for an non-scheduled event.
In entity_metadata: This type of event should not have entity metadata.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "pycord/discord/bot.py", line 511, in process_application_commands
    await ctx.command.invoke(ctx)
  File "pycord/discord/commands/commands.py", line 213, in invoke
    await injected(ctx)
  File "pycord/discord/commands/commands.py", line 103, in wrapped
    raise ApplicationCommandInvokeError(exc) from exc
discord.commands.errors.ApplicationCommandInvokeError: Application Command raised an exception: HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In channel_id: Cannot update the channel for an non-scheduled event.
In entity_metadata: This type of event should not have entity metadata.
```

### Intents

Tested with both no intents and the `guilds` intent :D

### System Information

note: I was testing this on my repo clone which explains the `pkg_resources`... The Pycord commit I was running it on was c602bc453450d018c5c4b876f9203431e7b5ff3b on master ofc.
```
- Python v3.8.5-final
- py-cord v2.0.0-alpha
    - py-cord pkg_resources: v1.7.3
- aiohttp v3.6.3
- system info: Darwin 20.6.0 Darwin Kernel Version 20.6.0: Wed Jun 23 00:26:31 PDT 2021; root:xnu-7195.141.2~5/RELEASE_X86_64
```

### Checklist

- [X] I have searched the open issues for duplicates.
- [X] I have shown the entire traceback, if possible.
- [X] I have removed my token from display, if visible.

### Additional Context

_No response_


Discussion:
Please define the event type the next time. That's the problem here
        location=ctx.author.voice.channel

is incorrect btw, it should be channel

Resolving patch:
diff --git a/discord/scheduled_events.py b/discord/scheduled_events.py
--- a/discord/scheduled_events.py
+++ b/discord/scheduled_events.py
@@ -80,7 +80,7 @@ class ScheduledEventLocation:
     def __init__(self, *, state: ConnectionState, location: Union[str, int, StageChannel, VoiceChannel]):
         self._state = state
         if isinstance(location, int):
-            self.value = self._state._get_channel(int(location))
+            self.value = self._state._get_guild_channel({"channel_id": int(location)})
         else:
             self.value = location
 
@@ -194,7 +194,7 @@ def __init__(self, *, state: ConnectionState, guild: Guild, creator: Optional[Me
         entity_metadata = data.get('entity_metadata')
         channel_id = data.get('channel_id', None)
         if channel_id != None:
-            self.location = ScheduledEventLocation(state=state, location=channel_id)
+            self.location = ScheduledEventLocation(state=state, location=int(channel_id))
         else:
             self.location = ScheduledEventLocation(state=state, location=entity_metadata["location"])
 
@@ -296,16 +296,16 @@ async def edit(
         if privacy_level is not MISSING:
             payload["privacy_level"] = int(privacy_level)
 
-        if not isinstance(location, ScheduledEventLocation):
-            location = ScheduledEventLocation(state=self._state, location=location)
-
         if location is not MISSING:
-            if location.type in (ScheduledEventLocationType.voice, ScheduledEventLocationType.stage_instance):
+            if not isinstance(location, (ScheduledEventLocation, utils._MissingSentinel)):
+                location = ScheduledEventLocation(state=self._state, location=location)
+
+            if location.type is ScheduledEventLocationType.external:
+                payload["channel_id"] = None
+                payload["entity_metadata"] = {"location": str(location.value)}
+            else:
                 payload["channel_id"] = location.value.id
                 payload["entity_metadata"] = None
-            else:
-                payload["channel_id"] = None
-                payload["entity_metadata"] = {"location":str(location.value)}
 
         location = location if location is not MISSING else self.location
         if end_time is MISSING and location.type is ScheduledEventLocationType.external:


Test patch: