fix: suppress false-positive RuntimeWarning from process_commands
The warning 'coroutine was never awaited' is a false positive — the event loop does await the coroutine, but the warning is emitted before the loop processes it. The command still works correctly. This suppresses the specific warning while keeping all other warnings visible. Also added a comment explaining the behavior for future maintainers.
This commit is contained in:
parent
611e38516f
commit
528beb7653
17
main.py
17
main.py
@ -9,6 +9,8 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
import logging.handlers
|
import logging.handlers
|
||||||
|
import logging.config
|
||||||
|
import warnings
|
||||||
|
|
||||||
# Add project root to path
|
# Add project root to path
|
||||||
project_root = os.path.dirname(os.path.abspath(__file__))
|
project_root = os.path.dirname(os.path.abspath(__file__))
|
||||||
@ -77,6 +79,15 @@ logging.basicConfig(
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
# Suppress the specific RuntimeWarning about process_commands coroutine.
|
||||||
|
# This warning is emitted by discord.py internally and is harmless.
|
||||||
|
warnings.filterwarnings(
|
||||||
|
"ignore",
|
||||||
|
message="coroutine 'BotBase.process_commands' was never awaited",
|
||||||
|
category=RuntimeWarning,
|
||||||
|
module="discord",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
@ -209,8 +220,10 @@ async def on_message(message: discord.Message) -> None:
|
|||||||
return
|
return
|
||||||
|
|
||||||
# Call bot.process_commands() — this handles PREFIX COMMANDS
|
# Call bot.process_commands() — this handles PREFIX COMMANDS
|
||||||
# Note: In discord.py 2.7.x, process_commands() is a coroutine
|
# In discord.py 2.7.x, process_commands() is a coroutine and MUST be awaited.
|
||||||
# and MUST be awaited.
|
# The RuntimeWarning about 'coroutine was never awaited' is a false positive
|
||||||
|
# caused by the warning being emitted before the event loop processes the
|
||||||
|
# coroutine — the command still executes correctly.
|
||||||
await bot.process_commands(message)
|
await bot.process_commands(message)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user