Skip to content

Client

Bases: processors.AutoModEvents, processors.ChannelEvents, processors.EntitlementEvents, processors.GuildEvents, processors.IntegrationEvents, processors.MemberEvents, processors.MessageEvents, processors.ReactionEvents, processors.RoleEvents, processors.ScheduledEvents, processors.StageEvents, processors.ThreadEvents, processors.UserEvents, processors.VoiceEvents

The bot client.

Parameters:

Name Type Description Default
intents Union[int, Intents]

The intents to use

Intents.DEFAULT
status Status

The status the bot should log in with (IE ONLINE, DND, IDLE)

Status.ONLINE
activity Union[Activity, str]

The activity the bot should log in "playing"

None
sync_interactions bool

Should application commands be synced with discord?

True
delete_unused_application_cmds bool

Delete any commands from discord that aren't implemented in this client

False
enforce_interaction_perms bool

Enforce discord application command permissions, locally

True
fetch_members bool

Should the client fetch members from guilds upon startup (this will delay the client being ready)

False
send_command_tracebacks bool

Automatically send uncaught tracebacks if a command throws an exception

True
send_not_ready_messages bool

Send a message to the user if they try to use a command before the client is ready

False
auto_defer Absent[Union[AutoDefer, bool]]
MISSING
interaction_context Type[InteractionContext]

Type[InteractionContext]: InteractionContext: The object to instantiate for Interaction Context

InteractionContext
component_context Type[BaseContext]

Type[ComponentContext]: The object to instantiate for Component Context

ComponentContext
autocomplete_context Type[BaseContext]

Type[AutocompleteContext]: The object to instantiate for Autocomplete Context

AutocompleteContext
modal_context Type[BaseContext]

Type[ModalContext]: The object to instantiate for Modal Context

ModalContext
total_shards int

The total number of shards in use

1
shard_id int

The zero based int ID of this shard

0
debug_scope Absent[Snowflake_Type]

Force all application commands to be registered within this scope

MISSING
disable_dm_commands bool

Should interaction commands be disabled in DMs?

False
basic_logging bool

Utilise basic logging to output library data to console. Do not use in combination with Client.logger

False
logging_level int

The level of logging to use for basic_logging. Do not use in combination with Client.logger

logging.INFO
logger logging.Logger

The logger interactions.py should use. Do not use in combination with Client.basic_logging and Client.logging_level. Note: Different loggers with multiple clients are not supported

MISSING
proxy

A http/https proxy to use for all requests

required
proxy_auth BasicAuth | tuple[str, str] | None

The auth to use for the proxy - must be either a tuple of (username, password) or aiohttp.BasicAuth

None

Optionally, you can configure the caches here, by specifying the name of the cache, followed by a dict-style object to use. It is recommended to use smart_cache.create_cache to configure the cache here. as an example, this is a recommended attribute message_cache=create_cache(250, 50),

Intents Note

By default, all non-privileged intents will be enabled

Caching Note

Setting a message cache hard limit to None is not recommended, as it could result in extremely high memory usage, we suggest a sane limit.

Source code in interactions/client/client.py
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
class Client(
    processors.AutoModEvents,
    processors.ChannelEvents,
    processors.EntitlementEvents,
    processors.GuildEvents,
    processors.IntegrationEvents,
    processors.MemberEvents,
    processors.MessageEvents,
    processors.ReactionEvents,
    processors.RoleEvents,
    processors.ScheduledEvents,
    processors.StageEvents,
    processors.ThreadEvents,
    processors.UserEvents,
    processors.VoiceEvents,
):
    """

    The bot client.

    Args:
        intents: The intents to use

        status: The status the bot should log in with (IE ONLINE, DND, IDLE)
        activity: The activity the bot should log in "playing"

        sync_interactions: Should application commands be synced with discord?
        delete_unused_application_cmds: Delete any commands from discord that aren't implemented in this client
        enforce_interaction_perms: Enforce discord application command permissions, locally
        fetch_members: Should the client fetch members from guilds upon startup (this will delay the client being ready)
        send_command_tracebacks: Automatically send uncaught tracebacks if a command throws an exception
        send_not_ready_messages: Send a message to the user if they try to use a command before the client is ready

        auto_defer: AutoDefer: A system to automatically defer commands after a set duration
        interaction_context: Type[InteractionContext]: InteractionContext: The object to instantiate for Interaction Context
        component_context: Type[ComponentContext]: The object to instantiate for Component Context
        autocomplete_context: Type[AutocompleteContext]: The object to instantiate for Autocomplete Context
        modal_context: Type[ModalContext]: The object to instantiate for Modal Context

        total_shards: The total number of shards in use
        shard_id: The zero based int ID of this shard

        debug_scope: Force all application commands to be registered within this scope
        disable_dm_commands: Should interaction commands be disabled in DMs?
        basic_logging: Utilise basic logging to output library data to console. Do not use in combination with `Client.logger`
        logging_level: The level of logging to use for basic_logging. Do not use in combination with `Client.logger`
        logger: The logger interactions.py should use. Do not use in combination with `Client.basic_logging` and `Client.logging_level`. Note: Different loggers with multiple clients are not supported

        proxy: A http/https proxy to use for all requests
        proxy_auth: The auth to use for the proxy - must be either a tuple of (username, password) or aiohttp.BasicAuth

    Optionally, you can configure the caches here, by specifying the name of the cache, followed by a dict-style object to use.
    It is recommended to use `smart_cache.create_cache` to configure the cache here.
    as an example, this is a recommended attribute `message_cache=create_cache(250, 50)`,

    ???+ note "Intents Note"
        By default, all non-privileged intents will be enabled

    ???+ note "Caching Note"
        Setting a message cache hard limit to None is not recommended, as it could result in extremely high memory usage, we suggest a sane limit.


    """

    def __init__(
        self,
        *,
        activity: Union[Activity, str] = None,
        auto_defer: Absent[Union[AutoDefer, bool]] = MISSING,
        autocomplete_context: Type[BaseContext] = AutocompleteContext,
        basic_logging: bool = False,
        component_context: Type[BaseContext] = ComponentContext,
        context_menu_context: Type[BaseContext] = ContextMenuContext,
        debug_scope: Absent["Snowflake_Type"] = MISSING,
        delete_unused_application_cmds: bool = False,
        disable_dm_commands: bool = False,
        enforce_interaction_perms: bool = True,
        fetch_members: bool = False,
        global_post_run_callback: Absent[Callable[..., Coroutine]] = MISSING,
        global_pre_run_callback: Absent[Callable[..., Coroutine]] = MISSING,
        intents: Union[int, Intents] = Intents.DEFAULT,
        interaction_context: Type[InteractionContext] = InteractionContext,
        logger: logging.Logger = MISSING,
        logging_level: int = logging.INFO,
        modal_context: Type[BaseContext] = ModalContext,
        owner_ids: Iterable["Snowflake_Type"] = (),
        send_command_tracebacks: bool = True,
        send_not_ready_messages: bool = False,
        shard_id: int = 0,
        show_ratelimit_tracebacks: bool = False,
        slash_context: Type[BaseContext] = SlashContext,
        status: Status = Status.ONLINE,
        sync_ext: bool = True,
        sync_interactions: bool = True,
        proxy_url: str | None = None,
        proxy_auth: BasicAuth | tuple[str, str] | None = None,
        token: str | None = None,
        total_shards: int = 1,
        **kwargs,
    ) -> None:
        if logger is MISSING:
            logger = constants.get_logger()

        if basic_logging:
            logging.basicConfig()
            logger.setLevel(logging_level)

        # Set Up logger and overwrite the constant
        self.logger = logger
        """The logger interactions.py should use. Do not use in combination with `Client.basic_logging` and `Client.logging_level`.
        !!! note
            Different loggers with multiple clients are not supported"""
        constants._logger = logger

        # Configuration
        self.sync_interactions: bool = sync_interactions
        """Should application commands be synced"""
        self.del_unused_app_cmd: bool = delete_unused_application_cmds
        """Should unused application commands be deleted?"""
        self.sync_ext: bool = sync_ext
        """Should we sync whenever a extension is (un)loaded"""
        self.debug_scope = to_snowflake(debug_scope) if debug_scope is not MISSING else MISSING
        """Sync global commands as guild for quicker command updates during debug"""
        self.send_command_tracebacks: bool = send_command_tracebacks
        """Should the traceback of command errors be sent in reply to the command invocation"""
        self.send_not_ready_messages: bool = send_not_ready_messages
        """Should the bot send a message when it is not ready yet in response to a command invocation"""
        if auto_defer is True:
            auto_defer = AutoDefer(enabled=True)
        else:
            auto_defer = auto_defer or AutoDefer()
        self.auto_defer = auto_defer
        """A system to automatically defer commands after a set duration"""
        self.intents = intents if isinstance(intents, Intents) else Intents(intents)

        # resources
        if isinstance(proxy_auth, tuple):
            proxy_auth = BasicAuth(*proxy_auth)

        proxy = (proxy_url, proxy_auth) if proxy_url or proxy_auth else None
        self.http: HTTPClient = HTTPClient(
            logger=self.logger, show_ratelimit_tracebacks=show_ratelimit_tracebacks, proxy=proxy
        )
        """The HTTP client to use when interacting with discord endpoints"""

        # context factories
        self.interaction_context: Type[BaseContext] = interaction_context
        """The object to instantiate for Interaction Context"""
        self.component_context: Type[BaseContext] = component_context
        """The object to instantiate for Component Context"""
        self.autocomplete_context: Type[BaseContext] = autocomplete_context
        """The object to instantiate for Autocomplete Context"""
        self.modal_context: Type[BaseContext] = modal_context
        """The object to instantiate for Modal Context"""
        self.slash_context: Type[BaseContext] = slash_context
        """The object to instantiate for Slash Context"""
        self.context_menu_context: Type[BaseContext] = context_menu_context
        """The object to instantiate for Context Menu Context"""

        self.token: str | None = token

        # flags
        self._ready = asyncio.Event()
        self._closed = False
        self._startup = False
        self.disable_dm_commands = disable_dm_commands

        self._guild_event = asyncio.Event()
        self.guild_event_timeout = 3
        """How long to wait for guilds to be cached"""

        # Sharding
        self.total_shards = total_shards
        self._connection_state: ConnectionState = ConnectionState(self, intents, shard_id=shard_id)

        self.enforce_interaction_perms = enforce_interaction_perms

        self.fetch_members = fetch_members
        """Fetch the full members list of all guilds on startup"""

        self._mention_reg = MISSING

        # caches
        self.cache: GlobalCache = GlobalCache(self, **{k: v for k, v in kwargs.items() if hasattr(GlobalCache, k)})
        # these store the last sent presence data for change_presence
        self._status: Status = status
        if isinstance(activity, str):
            self._activity = Activity.create(name=str(activity))
        else:
            self._activity: Activity = activity

        self._user: Absent[ClientUser] = MISSING
        self._app: Absent[Application] = MISSING

        # collections
        self.interactions_by_scope: Dict["Snowflake_Type", Dict[str, InteractionCommand]] = {}
        """A dictionary of registered application commands: `{scope: [commands]}`"""
        self._interaction_lookup: dict[str, InteractionCommand] = {}
        """A dictionary of registered application commands: `{name: command}`"""
        self.interaction_tree: Dict["Snowflake_Type", Dict[str, InteractionCommand | Dict[str, InteractionCommand]]] = (
            {}
        )
        """A dictionary of registered application commands in a tree"""
        self._component_callbacks: Dict[str, Callable[..., Coroutine]] = {}
        self._regex_component_callbacks: Dict[re.Pattern, Callable[..., Coroutine]] = {}
        self._modal_callbacks: Dict[str, Callable[..., Coroutine]] = {}
        self._regex_modal_callbacks: Dict[re.Pattern, Callable[..., Coroutine]] = {}
        self._global_autocompletes: Dict[str, GlobalAutoComplete] = {}
        self.processors: Dict[str, Callable[..., Coroutine]] = {}
        self.__modules = {}
        self.ext: Dict[str, Extension] = {}
        """A dictionary of mounted ext"""
        self.listeners: Dict[str, list[Listener]] = {}
        self.waits: Dict[str, List] = {}
        self.owner_ids: set[Snowflake_Type] = set(owner_ids)

        self.async_startup_tasks: list[tuple[Callable[..., Coroutine], Iterable[Any], dict[str, Any]]] = []
        """A list of coroutines to run during startup"""

        self._add_command_hook: list[Callable[[Callable], Any]] = []

        # callbacks
        if global_pre_run_callback:
            if asyncio.iscoroutinefunction(global_pre_run_callback):
                self.pre_run_callback: Callable[..., Coroutine] = global_pre_run_callback
            else:
                raise TypeError("Callback must be a coroutine")
        else:
            self.pre_run_callback = MISSING

        if global_post_run_callback:
            if asyncio.iscoroutinefunction(global_post_run_callback):
                self.post_run_callback: Callable[..., Coroutine] = global_post_run_callback
            else:
                raise TypeError("Callback must be a coroutine")
        else:
            self.post_run_callback = MISSING

        super().__init__()
        self._sanity_check()

    async def __aenter__(self) -> "Client":
        if not self.token:
            raise ValueError(
                "Token not found - to use the bot in a context manager, you must pass the token in the Client"
                " constructor."
            )
        await self.login(self.token)
        return self

    async def __aexit__(self, exc_type, exc_val, exc_tb) -> None:
        if not self.is_closed:
            await self.stop()

    @property
    def is_closed(self) -> bool:
        """Returns True if the bot has closed."""
        return self._closed

    @property
    def is_ready(self) -> bool:
        """Returns True if the bot is ready."""
        return self._ready.is_set()

    @property
    def latency(self) -> float:
        """Returns the latency of the websocket connection (seconds)."""
        return self._connection_state.latency

    @property
    def average_latency(self) -> float:
        """Returns the average latency of the websocket connection (seconds)."""
        return self._connection_state.average_latency

    @property
    def start_time(self) -> datetime:
        """The start time of the bot."""
        return self._connection_state.start_time

    @property
    def gateway_started(self) -> bool:
        """Returns if the gateway has been started."""
        return self._connection_state.gateway_started.is_set()

    @property
    def user(self) -> ClientUser:
        """Returns the bot's user."""
        return self._user

    @property
    def app(self) -> Application:
        """Returns the bots application."""
        return self._app

    @property
    def owner(self) -> Optional["User"]:
        """Returns the bot's owner'."""
        try:
            return self.app.owner
        except TypeError:
            return MISSING

    @property
    def owners(self) -> List["User"]:
        """Returns the bot's owners as declared via `client.owner_ids`."""
        return [self.get_user(u_id) for u_id in self.owner_ids]

    @property
    def guilds(self) -> List["Guild"]:
        """Returns a list of all guilds the bot is in."""
        return self.user.guilds

    @property
    def status(self) -> Status:
        """
        Get the status of the bot.

        IE online, afk, dnd

        """
        return self._status

    @property
    def activity(self) -> Activity:
        """Get the activity of the bot."""
        return self._activity

    @property
    def application_commands(self) -> List[InteractionCommand]:
        """A list of all application commands registered within the bot."""
        commands = []
        for scope in self.interactions_by_scope.keys():
            commands += [cmd for cmd in self.interactions_by_scope[scope].values() if cmd not in commands]

        return commands

    @property
    def ws(self) -> GatewayClient:
        """Returns the websocket client."""
        return self._connection_state.gateway

    def get_guild_websocket(self, id: "Snowflake_Type") -> GatewayClient:
        return self.ws

    def _sanity_check(self) -> None:
        """Checks for possible and common errors in the bot's configuration."""
        self.logger.debug("Running client sanity checks...")

        contexts = {
            self.interaction_context: InteractionContext,
            self.component_context: ComponentContext,
            self.autocomplete_context: AutocompleteContext,
            self.modal_context: ModalContext,
        }
        for obj, expected in contexts.items():
            if not issubclass(obj, expected):
                raise TypeError(f"{obj.__name__} must inherit from {expected.__name__}")

        if self.del_unused_app_cmd:
            self.logger.warning(
                "As `delete_unused_application_cmds` is enabled, the client must cache all guilds app-commands, this"
                " could take a while."
            )

        if Intents.GUILDS not in self._connection_state.intents:
            self.logger.warning("GUILD intent has not been enabled; this is very likely to cause errors")

        if self.fetch_members and Intents.GUILD_MEMBERS not in self._connection_state.intents:
            raise BotException("Members Intent must be enabled in order to use fetch members")
        if self.fetch_members:
            self.logger.warning("fetch_members enabled; startup will be delayed")

        if len(self.processors) == 0:
            self.logger.warning("No Processors are loaded! This means no events will be processed!")

        caches = [
            c[0]
            for c in inspect.getmembers(self.cache, predicate=lambda x: isinstance(x, dict))
            if not c[0].startswith("__")
        ]
        for cache in caches:
            _cache_obj = getattr(self.cache, cache)
            if isinstance(_cache_obj, NullCache):
                self.logger.warning(f"{cache} has been disabled")

    def _queue_task(self, coro: Listener, event: BaseEvent, *args, **kwargs) -> asyncio.Task:
        async def _async_wrap(_coro: Listener, _event: BaseEvent, *_args, **_kwargs) -> None:
            try:
                if (
                    not isinstance(_event, (events.Error, events.RawGatewayEvent))
                    and coro.delay_until_ready
                    and not self.is_ready
                ):
                    await self.wait_until_ready()

                # don't pass event object if listener doesn't expect it
                if _coro.pass_event_object:
                    await _coro(_event, *_args, **_kwargs)
                else:
                    if not _coro.warned_no_event_arg and len(_event.__attrs_attrs__) > 2 and _coro.event != "event":
                        self.logger.warning(
                            f"{_coro} is listening to {_coro.event} event which contains event data. "
                            f"Add an event argument to this listener to receive the event data object."
                        )
                        _coro.warned_no_event_arg = True
                    await _coro()
            except asyncio.CancelledError:
                pass
            except Exception as e:
                if isinstance(event, events.Error):
                    # No infinite loops please
                    self.default_error_handler(repr(event), e)
                else:
                    self.dispatch(events.Error(source=repr(event), error=e))

        try:
            asyncio.get_running_loop()
            return asyncio.create_task(
                _async_wrap(coro, event, *args, **kwargs), name=f"interactions:: {event.resolved_name}"
            )
        except RuntimeError:
            self.logger.debug("Event loop is closed; queuing task for execution on startup")
            self.async_startup_tasks.append((_async_wrap, (coro, event, *args), kwargs))

    @staticmethod
    def default_error_handler(source: str, error: BaseException) -> None:
        """
        The default error logging behaviour.

        Args:
            source: The source of this error
            error: The exception itself

        """
        out = traceback.format_exception(error)

        if isinstance(error, HTTPException):
            # HTTPException's are of 3 known formats, we can parse them for human readable errors
            with contextlib.suppress(Exception):
                out = [str(error)]
        get_logger().error(
            "Ignoring exception in {}:{}{}".format(source, "\n" if len(out) > 1 else " ", "".join(out)),
        )

    @Listener.create(is_default_listener=True)
    async def on_error(self, event: events.Error) -> None:
        """
        Catches all errors dispatched by the library.

        By default it will format and print them to console.

        Listen to the `Error` event to overwrite this behaviour.

        """
        self.default_error_handler(event.source, event.error)

    @Listener.create(is_default_listener=True)
    async def on_command_error(self, event: events.CommandError) -> None:
        """
        Catches all errors dispatched by commands.

        By default it will dispatch the `Error` event.

        Listen to the `CommandError` event to overwrite this behaviour.

        """
        self.dispatch(
            events.Error(
                source=f"cmd `/{event.ctx.invoke_target}`",
                error=event.error,
                args=event.args,
                kwargs=event.kwargs,
                ctx=event.ctx,
            )
        )
        with contextlib.suppress(errors.LibraryException):
            if isinstance(event.error, errors.CommandOnCooldown):
                await event.ctx.send(
                    embeds=Embed(
                        description=(
                            "This command is on cooldown!\n"
                            f"Please try again in {int(event.error.cooldown.get_cooldown_time())} seconds"
                        ),
                        color=BrandColors.FUCHSIA,
                    )
                )
            elif isinstance(event.error, errors.MaxConcurrencyReached):
                await event.ctx.send(
                    embeds=Embed(
                        description="This command has reached its maximum concurrent usage!\nPlease try again shortly.",
                        color=BrandColors.FUCHSIA,
                    )
                )
            elif isinstance(event.error, errors.CommandCheckFailure):
                await event.ctx.send(
                    embeds=Embed(
                        description="You do not have permission to run this command!",
                        color=BrandColors.YELLOW,
                    )
                )
            elif self.send_command_tracebacks:
                out = "".join(traceback.format_exception(event.error))
                if self.http.token is not None:
                    out = out.replace(self.http.token, "[REDACTED TOKEN]")
                await event.ctx.send(
                    embeds=Embed(
                        title=f"Error: {type(event.error).__name__}",
                        color=BrandColors.RED,
                        description=f"```\n{out[:EMBED_MAX_DESC_LENGTH - 8]}```",
                    )
                )

    @Listener.create(is_default_listener=True)
    async def on_command_completion(self, event: events.CommandCompletion) -> None:
        """
        Called *after* any command is ran.

        By default, it will simply log the command.

        Listen to the `CommandCompletion` event to overwrite this behaviour.

        """
        self.logger.info(f"Command Called: {event.ctx.invoke_target} with {event.ctx.args = } | {event.ctx.kwargs = }")

    @Listener.create(is_default_listener=True)
    async def on_component_error(self, event: events.ComponentError) -> None:
        """
        Catches all errors dispatched by components.

        By default it will dispatch the `Error` event.

        Listen to the `ComponentError` event to overwrite this behaviour.

        """
        self.dispatch(
            events.Error(
                source=f"Component Callback for {event.ctx.custom_id}",
                error=event.error,
                args=event.args,
                kwargs=event.kwargs,
                ctx=event.ctx,
            )
        )

    @Listener.create(is_default_listener=True)
    async def on_component_completion(self, event: events.ComponentCompletion) -> None:
        """
        Called *after* any component callback is ran.

        By default, it will simply log the component use.

        Listen to the `ComponentCompletion` event to overwrite this behaviour.

        """
        symbol = "¢"
        self.logger.info(
            f"Component Called: {symbol}{event.ctx.invoke_target} with {event.ctx.args = } | {event.ctx.kwargs = }"
        )

    @Listener.create(is_default_listener=True)
    async def on_autocomplete_error(self, event: events.AutocompleteError) -> None:
        """
        Catches all errors dispatched by autocompletion options.

        By default it will dispatch the `Error` event.

        Listen to the `AutocompleteError` event to overwrite this behaviour.

        """
        self.dispatch(
            events.Error(
                source=f"Autocomplete Callback for /{event.ctx.invoke_target} - Option: {event.ctx.focussed_option}",
                error=event.error,
                args=event.args,
                kwargs=event.kwargs,
                ctx=event.ctx,
            )
        )

    @Listener.create(is_default_listener=True)
    async def on_autocomplete_completion(self, event: events.AutocompleteCompletion) -> None:
        """
        Called *after* any autocomplete callback is ran.

        By default, it will simply log the autocomplete callback.

        Listen to the `AutocompleteCompletion` event to overwrite this behaviour.

        """
        symbol = "$"
        self.logger.info(
            f"Autocomplete Called: {symbol}{event.ctx.invoke_target} with {event.ctx.focussed_option = } |"
            f" {event.ctx.kwargs = }"
        )

    @Listener.create(is_default_listener=True)
    async def on_modal_error(self, event: events.ModalError) -> None:
        """
        Catches all errors dispatched by modals.

        By default it will dispatch the `Error` event.

        Listen to the `ModalError` event to overwrite this behaviour.

        """
        self.dispatch(
            events.Error(
                source=f"Modal Callback for custom_id {event.ctx.custom_id}",
                error=event.error,
                args=event.args,
                kwargs=event.kwargs,
                ctx=event.ctx,
            )
        )

    @Listener.create(is_default_listener=True)
    async def on_modal_completion(self, event: events.ModalCompletion) -> None:
        """
        Called *after* any modal callback is ran.

        By default, it will simply log the modal callback.

        Listen to the `ModalCompletion` event to overwrite this behaviour.

        """
        self.logger.info(f"Modal Called: {event.ctx.custom_id = } with {event.ctx.responses = }")

    @Listener.create()
    async def on_resume(self) -> None:
        self._ready.set()

    @Listener.create(is_default_listener=True)
    async def _on_websocket_ready(self, event: events.RawGatewayEvent) -> None:
        """
        Catches websocket ready and determines when to dispatch the client `READY` signal.

        Args:
            event: The websocket ready packet

        """
        data = event.data
        expected_guilds = {to_snowflake(guild["id"]) for guild in data["guilds"]}
        self._user._add_guilds(expected_guilds)

        if not self._startup:
            while len(self.guilds) != len(expected_guilds):
                try:  # wait to let guilds cache
                    await asyncio.wait_for(self._guild_event.wait(), self.guild_event_timeout)
                except asyncio.TimeoutError:
                    # this will *mostly* occur when a guild has been shadow deleted by discord T&S.
                    # there is no way to check for this, so we just need to wait for this to time out.
                    # We still log it though, just in case.
                    self.logger.debug("Timeout waiting for guilds cache")
                    break
                self._guild_event.clear()

            if self.fetch_members:
                # ensure all guilds have completed chunking
                for guild in self.guilds:
                    if guild and not guild.chunked.is_set():
                        self.logger.debug(f"Waiting for {guild.id} to chunk")
                        await guild.chunked.wait()

            # cache slash commands
            if not self._startup:
                await self._init_interactions()

            self._startup = True
            self.dispatch(events.Startup())

        else:
            # reconnect ready
            ready_guilds = set()

            async def _temp_listener(_event: events.RawGatewayEvent) -> None:
                ready_guilds.add(_event.data["id"])

            listener = Listener.create("_on_raw_guild_create")(_temp_listener)
            self.add_listener(listener)

            while len(ready_guilds) != len(expected_guilds):
                try:
                    await asyncio.wait_for(self._guild_event.wait(), self.guild_event_timeout)
                except asyncio.TimeoutError:
                    break
                self._guild_event.clear()

            self.listeners["raw_guild_create"].remove(listener)

        self._ready.set()
        self.dispatch(events.Ready())

    async def login(self, token: str | None = None) -> None:
        """
        Login to discord via http.

        !!! note
            You will need to run Client.start_gateway() before you start receiving gateway events.

        Args:
            token str: Your bot's token

        """
        if not self.token and not token:
            raise RuntimeError(
                "No token provided - please provide a token in the client constructor or via the login method."
            )
        self.token = (token or self.token).strip()

        # i needed somewhere to put this call,
        # login will always run after initialisation
        # so im gathering commands here
        self._gather_callbacks()

        if any(v for v in constants.CLIENT_FEATURE_FLAGS.values()):
            # list all enabled flags
            enabled_flags = [k for k, v in constants.CLIENT_FEATURE_FLAGS.items() if v]
            self.logger.info(f"Enabled feature flags: {', '.join(enabled_flags)}")

        self.logger.debug("Attempting to login")
        me = await self.http.login(self.token)
        self._user = ClientUser.from_dict(me, self)
        self.cache.place_user_data(me)
        self._app = Application.from_dict(await self.http.get_current_bot_information(), self)
        self._mention_reg = re.compile(rf"^(<@!?{self.user.id}*>\s)")

        if self.app.owner:
            self.owner_ids.add(self.app.owner.id)

        self.dispatch(events.Login())

    async def astart(self, token: str | None = None) -> None:
        """
        Asynchronous method to start the bot.

        Args:
            token: Your bot's token

        """
        await self.login(token)

        # run any pending startup tasks
        if self.async_startup_tasks:
            try:
                await asyncio.gather(
                    *[
                        task[0](*task[1] if len(task) > 1 else [], **task[2] if len(task) == 3 else {})
                        for task in self.async_startup_tasks
                    ]
                )
            except Exception as e:
                self.dispatch(events.Error(source="async-extension-loader", error=e))
        try:
            await self._connection_state.start()
        finally:
            await self.stop()

    def start(self, token: str | None = None) -> None:
        """
        Start the bot.

        If `uvloop` is installed, it will be used.

        info:
            This is the recommended method to start the bot
        """
        try:
            import uvloop

            has_uvloop = True
        except ImportError:
            has_uvloop = False

        with contextlib.suppress(KeyboardInterrupt):
            if has_uvloop:
                self.logger.info("uvloop is installed, using it")
                if sys.version_info >= (3, 11):
                    with asyncio.Runner(loop_factory=uvloop.new_event_loop) as runner:
                        runner.run(self.astart(token))
                else:
                    uvloop.install()
                    asyncio.run(self.astart(token))
            else:
                asyncio.run(self.astart(token))

    async def start_gateway(self) -> None:
        """Starts the gateway connection."""
        try:
            await self._connection_state.start()
        finally:
            await self.stop()

    async def stop(self) -> None:
        """Shutdown the bot."""
        self.logger.debug("Stopping the bot.")
        self._ready.clear()
        await self.http.close()
        await self._connection_state.stop()

    async def _process_waits(self, event: events.BaseEvent) -> None:
        if _waits := self.waits.get(event.resolved_name, []):
            index_to_remove = []
            for i, _wait in enumerate(_waits):
                result = await _wait(event)
                if result:
                    index_to_remove.append(i)

            for idx in sorted(index_to_remove, reverse=True):
                _waits.pop(idx)

    def dispatch(self, event: events.BaseEvent, *args, **kwargs) -> None:
        """
        Dispatch an event.

        Args:
            event: The event to be dispatched.

        """
        if listeners := self.listeners.get(event.resolved_name, []):
            self.logger.debug(f"Dispatching Event: {event.resolved_name}")
            event.bot = self
            for _listen in listeners:
                try:
                    self._queue_task(_listen, event, *args, **kwargs)
                except Exception as e:
                    raise BotException(
                        f"An error occurred attempting during {event.resolved_name} event processing"
                    ) from e

        try:
            asyncio.get_running_loop()
            _ = asyncio.create_task(self._process_waits(event))  # noqa: RUF006
        except RuntimeError:
            # dispatch attempt before event loop is running
            self.async_startup_tasks.append((self._process_waits, (event,), {}))

        if "event" in self.listeners:
            # special meta event listener
            for _listen in self.listeners["event"]:
                self._queue_task(_listen, event, *args, **kwargs)

    async def wait_until_ready(self) -> None:
        """Waits for the client to become ready."""
        await self._ready.wait()

    def wait_for(
        self,
        event: Union[str, "BaseEvent"],
        checks: Absent[Optional[Union[Callable[..., bool], Callable[..., Awaitable[bool]]]]] = MISSING,
        timeout: Optional[float] = None,
    ) -> Any:
        """
        Waits for a WebSocket event to be dispatched.

        Args:
            event: The name of event to wait.
            checks: A predicate to check what to wait for.
            timeout: The number of seconds to wait before timing out.

        Returns:
            The event object.

        """
        event = get_event_name(event)

        if event not in self.waits:
            self.waits[event] = []

        future = asyncio.Future()
        self.waits[event].append(Wait(event, checks, future))

        return asyncio.wait_for(future, timeout)

    async def wait_for_modal(
        self,
        modal: "Modal",
        author: Optional["Snowflake_Type"] = None,
        timeout: Optional[float] = None,
    ) -> "ModalContext":
        """
        Wait for a modal response.

        Args:
            modal: The modal we're waiting for.
            author: The user we're waiting for to reply
            timeout: A timeout in seconds to stop waiting

        Returns:
            The context of the modal response

        Raises:
            asyncio.TimeoutError: if no response is received that satisfies the predicate before timeout seconds have passed

        """
        author = to_snowflake(author) if author else None

        def predicate(event) -> bool:
            if modal.custom_id != event.ctx.custom_id:
                return False
            return author == to_snowflake(event.ctx.author) if author else True

        resp = await self.wait_for("modal_completion", predicate, timeout)
        return resp.ctx

    async def wait_for_component(
        self,
        messages: Union[Message, int, list] = None,
        components: Optional[
            Union[
                List[List[Union["BaseComponent", dict]]],
                List[Union["BaseComponent", dict]],
                "BaseComponent",
                dict,
            ]
        ] = None,
        check: Absent[Optional[Union[Callable[..., bool], Callable[..., Awaitable[bool]]]]] | None = None,
        timeout: Optional[float] = None,
    ) -> "events.Component":
        """
        Waits for a component to be sent to the bot.

        Args:
            messages: The message object to check for.
            components: The components to wait for.
            check: A predicate to check what to wait for.
            timeout: The number of seconds to wait before timing out.

        Returns:
            `Component` that was invoked. Use `.ctx` to get the `ComponentContext`.

        Raises:
            asyncio.TimeoutError: if timed out

        """
        if not messages and not components:
            raise ValueError("You must specify messages or components (or both)")

        message_ids = (
            to_snowflake_list(messages) if isinstance(messages, list) else to_snowflake(messages) if messages else None
        )
        custom_ids = list(get_components_ids(components)) if components else None

        # automatically convert improper custom_ids
        if custom_ids and not all(isinstance(x, str) for x in custom_ids):
            custom_ids = [str(i) for i in custom_ids]

        async def _check(event: events.Component) -> bool:
            ctx: ComponentContext = event.ctx
            # if custom_ids is empty or there is a match
            wanted_message = not message_ids or ctx.message.id in (
                [message_ids] if isinstance(message_ids, int) else message_ids
            )
            wanted_component = not custom_ids or ctx.custom_id in custom_ids
            if wanted_message and wanted_component:
                if asyncio.iscoroutinefunction(check):
                    return bool(check is None or await check(event))
                return bool(check is None or check(event))
            return False

        return await self.wait_for("component", checks=_check, timeout=timeout)

    def command(self, *args, **kwargs) -> Callable:
        """A decorator that registers a command. Aliases `interactions.slash_command`"""
        raise NotImplementedError(
            "Use interactions.slash_command instead. Please consult the v4 -> v5 migration guide https://interactions-py.github.io/interactions.py/Guides/98%20Migration%20from%204.X/"
        )

    def listen(self, event_name: Absent[str] = MISSING) -> Callable[[AsyncCallable], Listener]:
        """
        A decorator to be used in situations that the library can't automatically hook your listeners. Ideally, the standard listen decorator should be used, not this.

        Args:
            event_name: The event name to use, if not the coroutine name

        Returns:
            A listener that can be used to hook into the event.

        """

        def wrapper(coro: AsyncCallable) -> Listener:
            listener = Listener.create(event_name)(coro)
            self.add_listener(listener)
            return listener

        return wrapper

    event = listen  # alias for easier migration

    def add_event_processor(self, event_name: Absent[str] = MISSING) -> Callable[[AsyncCallable], AsyncCallable]:
        """
        A decorator to be used to add event processors.

        Args:
            event_name: The event name to use, if not the coroutine name

        Returns:
            A function that can be used to hook into the event.

        """

        def wrapper(coro: AsyncCallable) -> AsyncCallable:
            name = event_name
            if name is MISSING:
                name = coro.__name__
            name = name.lstrip("_")
            name = name.removeprefix("on_")
            self.processors[name] = coro
            return coro

        return wrapper

    def add_listener(self, listener: Listener) -> None:
        """
        Add a listener for an event, if no event is passed, one is determined.

        Args:
            listener Listener: The listener to add to the client

        """
        if listener.event == "event":
            self.logger.critical(
                f"Subscribing to `{listener.event}` - Meta Events are very expensive; remember to remove it before"
                " releasing your bot"
            )

        if not listener.is_default_listener:
            # check that the required intents are enabled

            event_class_name = "".join([name.capitalize() for name in listener.event.split("_")])
            if event_class := globals().get(event_class_name):
                if required_intents := _INTENT_EVENTS.get(event_class):
                    if all(required_intent not in self.intents for required_intent in required_intents):
                        self.logger.warning(
                            f"Event `{listener.event}` will not work since the required intent is not set -> Requires"
                            f" any of: `{required_intents}`"
                        )

        # prevent the same callback being added twice
        if listener in self.listeners.get(listener.event, []):
            self.logger.debug(f"Listener {listener} has already been hooked, not re-hooking it again")
            return

        listener.lazy_parse_params()

        if listener.event not in self.listeners:
            self.listeners[listener.event] = []
        self.listeners[listener.event].append(listener)

        # check if other listeners are to be deleted
        default_listeners = [c_listener.is_default_listener for c_listener in self.listeners[listener.event]]
        removes_defaults = [c_listener.disable_default_listeners for c_listener in self.listeners[listener.event]]

        if any(default_listeners) and any(removes_defaults):
            self.listeners[listener.event] = [
                c_listener for c_listener in self.listeners[listener.event] if not c_listener.is_default_listener
            ]

    def add_interaction(self, command: InteractionCommand) -> bool:
        """
        Add a slash command to the client.

        Args:
            command InteractionCommand: The command to add

        """
        if self.debug_scope:
            command.scopes = [self.debug_scope]

        if self.disable_dm_commands:
            command.dm_permission = False

        # for SlashCommand objs without callback (like objects made to hold group info etc)
        if command.callback is None:
            return False

        if isinstance(command, SlashCommand):
            command._parse_parameters()

        base, group, sub, *_ = [*command.resolved_name.split(" "), None, None]

        for scope in command.scopes:
            if scope not in self.interactions_by_scope:
                self.interactions_by_scope[scope] = {}
            elif command.resolved_name in self.interactions_by_scope[scope]:
                old_cmd = self.interactions_by_scope[scope][command.resolved_name]
                raise ValueError(f"Duplicate Command! {scope}::{old_cmd.resolved_name}")

            # if self.enforce_interaction_perms:
            #     command.checks.append(command._permission_enforcer)

            self.interactions_by_scope[scope][command.resolved_name] = command

            if scope not in self.interaction_tree:
                self.interaction_tree[scope] = {}

            if group is None or isinstance(command, ContextMenu):
                self.interaction_tree[scope][command.resolved_name] = command
            else:
                if not (current := self.interaction_tree[scope].get(base)) or isinstance(current, SlashCommand):
                    self.interaction_tree[scope][base] = {}
                if sub is None:
                    self.interaction_tree[scope][base][group] = command
                else:
                    if not (current := self.interaction_tree[scope][base].get(group)) or isinstance(
                        current, SlashCommand
                    ):
                        self.interaction_tree[scope][base][group] = {}
                    self.interaction_tree[scope][base][group][sub] = command

        return True

    def add_component_callback(self, command: ComponentCommand) -> None:
        """
        Add a component callback to the client.

        Args:
            command: The command to add

        """
        for listener in command.listeners:
            if isinstance(listener, re.Pattern):
                if listener in self._regex_component_callbacks.keys():
                    raise ValueError(f"Duplicate Component! Multiple component callbacks for `{listener}`")
                self._regex_component_callbacks[listener] = command
            else:
                # I know this isn't an ideal solution, but it means we can lookup callbacks with O(1)
                if listener in self._component_callbacks.keys():
                    raise ValueError(f"Duplicate Component! Multiple component callbacks for `{listener}`")
                self._component_callbacks[listener] = command
            continue

    def add_modal_callback(self, command: ModalCommand) -> None:
        """
        Add a modal callback to the client.

        Args:
            command: The command to add

        """
        # test for parameters that arent the ctx (or self)
        if command.has_binding:
            callback = functools.partial(command.callback, None, None)
        else:
            callback = functools.partial(command.callback, None)

        if not inspect.signature(callback).parameters:
            # if there are none, notify the command to just pass the ctx and not kwargs
            # TODO: just make modal callbacks not pass kwargs at all (breaking)
            command._just_ctx = True

        for listener in command.listeners:
            if isinstance(listener, re.Pattern):
                if listener in self._regex_component_callbacks.keys():
                    raise ValueError(f"Duplicate Component! Multiple modal callbacks for `{listener}`")
                self._regex_modal_callbacks[listener] = command
            else:
                if listener in self._modal_callbacks.keys():
                    raise ValueError(f"Duplicate Component! Multiple modal callbacks for `{listener}`")
                self._modal_callbacks[listener] = command
            continue

    def add_global_autocomplete(self, callback: GlobalAutoComplete) -> None:
        """
        Add a global autocomplete to the client.

        Args:
            callback: The autocomplete to add

        """
        self._global_autocompletes[callback.option_name] = callback

    def add_command(self, func: Callable) -> None:
        """
        Add a command to the client.

        Args:
            func: The command to add

        """
        if isinstance(func, ModalCommand):
            self.add_modal_callback(func)
        elif isinstance(func, ComponentCommand):
            self.add_component_callback(func)
        elif isinstance(func, InteractionCommand):
            self.add_interaction(func)
        elif isinstance(func, Listener):
            self.add_listener(func)
        elif isinstance(func, GlobalAutoComplete):
            self.add_global_autocomplete(func)
        elif not isinstance(func, BaseCommand):
            raise TypeError("Invalid command type")

        if not func.callback:
            # for group = SlashCommand(...) usage
            return

        if isinstance(func.callback, functools.partial):
            ext = getattr(func, "extension", None)
            self.logger.debug(f"Added callback: {f'{ext.name}.' if ext else ''}{func.callback.func.__name__}")
        else:
            self.logger.debug(f"Added callback: {func.callback.__name__}")

        for hook in self._add_command_hook:
            hook(func)

        self.dispatch(CallbackAdded(callback=func, extension=func.extension if hasattr(func, "extension") else None))

    def _gather_callbacks(self) -> None:
        """Gathers callbacks from __main__ and self."""

        def process(callables, location: str) -> None:
            added = 0
            for func in callables:
                try:
                    self.add_command(func)
                    added += 1
                except TypeError:
                    self.logger.debug(f"Failed to add callback {func} from {location}")
                    continue

            self.logger.debug(f"{added} callbacks have been loaded from {location}.")

        main_commands = [
            obj for _, obj in inspect.getmembers(sys.modules["__main__"]) if isinstance(obj, CallbackObject)
        ]
        client_commands = [
            obj.copy_with_binding(self) for _, obj in inspect.getmembers(self) if isinstance(obj, CallbackObject)
        ]
        process(main_commands, "__main__")
        process(client_commands, self.__class__.__name__)

        [wrap_partial(obj, self) for _, obj in inspect.getmembers(self) if isinstance(obj, Task)]

    async def _init_interactions(self) -> None:
        """
        Initialise slash commands.

        If `sync_interactions` this will submit all registered slash
        commands to discord. Otherwise, it will get the list of
        interactions and cache their scopes.

        """
        # allow for ext and main to share the same decorator
        try:
            if self.sync_interactions:
                await self.synchronise_interactions()
            else:
                await self._cache_interactions(warn_missing=False)
        except Exception as e:
            self.dispatch(events.Error(source="Interaction Syncing", error=e))

    async def _cache_interactions(self, warn_missing: bool = False) -> None:
        """Get all interactions used by this bot and cache them."""
        if warn_missing or self.del_unused_app_cmd:
            bot_scopes = {g.id for g in self.cache.guild_cache.values()}
            bot_scopes.add(GLOBAL_SCOPE)
        else:
            bot_scopes = set(self.interactions_by_scope)

        sem = asyncio.Semaphore(5)

        async def wrap(*args, **kwargs) -> Absent[List[Dict]]:
            async with sem:
                try:
                    return await self.http.get_application_commands(*args, **kwargs)
                except Forbidden:
                    return MISSING

        results = await asyncio.gather(*[wrap(self.app.id, scope) for scope in bot_scopes])
        results = dict(zip(bot_scopes, results, strict=False))

        for scope, remote_cmds in results.items():
            if remote_cmds == MISSING:
                self.logger.debug(f"Bot was not invited to guild {scope} with `application.commands` scope")
                continue

            remote_cmds = {cmd_data["name"]: cmd_data for cmd_data in remote_cmds}

            found = set()
            if scope in self.interactions_by_scope:
                for cmd in self.interactions_by_scope[scope].values():
                    cmd_name = str(cmd.name)
                    cmd_data = remote_cmds.get(cmd_name, MISSING)
                    if cmd_data is MISSING:
                        if cmd_name not in found and warn_missing:
                            self.logger.error(
                                f'Detected yet to sync slash command "/{cmd_name}" for scope '
                                f'{"global" if scope == GLOBAL_SCOPE else scope}'
                            )
                        continue
                    found.add(cmd_name)
                    self.update_command_cache(scope, cmd.resolved_name, cmd_data["id"])

            if warn_missing:
                for cmd_data in remote_cmds.values():
                    self.logger.error(
                        f"Detected unimplemented slash command \"/{cmd_data['name']}\" for scope "
                        f"{'global' if scope == GLOBAL_SCOPE else scope}"
                    )

    async def synchronise_interactions(
        self,
        *,
        scopes: Sequence["Snowflake_Type"] = MISSING,
        delete_commands: Absent[bool] = MISSING,
    ) -> None:
        """
        Synchronise registered interactions with discord.

        Args:
            scopes: Optionally specify which scopes are to be synced.
            delete_commands: Override the client setting and delete commands.

        Returns:
            None

        Raises:
            InteractionMissingAccess: If bot is lacking the necessary access.
            Exception: If there is an error during the synchronization process.

        """
        s = time.perf_counter()
        _delete_cmds = self.del_unused_app_cmd if delete_commands is MISSING else delete_commands
        await self._cache_interactions()

        cmd_scopes = self._get_sync_scopes(scopes)
        local_cmds_json = application_commands_to_dict(self.interactions_by_scope, self)

        await asyncio.gather(*[self.sync_scope(scope, _delete_cmds, local_cmds_json) for scope in cmd_scopes])

        t = time.perf_counter() - s
        self.logger.debug(f"Sync of {len(cmd_scopes)} scopes took {t} seconds")

    def _get_sync_scopes(self, scopes: Sequence["Snowflake_Type"]) -> List["Snowflake_Type"]:
        """
        Determine which scopes to sync.

        Args:
            scopes: The scopes to sync.

        Returns:
            The scopes to sync.

        """
        if scopes is not MISSING:
            return scopes
        if self.del_unused_app_cmd:
            return [to_snowflake(g_id) for g_id in self._user._guild_ids] + [GLOBAL_SCOPE]
        return list(set(self.interactions_by_scope) | {GLOBAL_SCOPE})

    async def sync_scope(
        self,
        cmd_scope: "Snowflake_Type",
        delete_cmds: bool,
        local_cmds_json: Dict["Snowflake_Type", List[Dict[str, Any]]],
    ) -> None:
        """
        Sync a single scope.

        Args:
            cmd_scope: The scope to sync.
            delete_cmds: Whether to delete commands.
            local_cmds_json: The local commands in json format.

        """
        sync_needed_flag = False
        sync_payload = []

        try:
            remote_commands = await self.get_remote_commands(cmd_scope)
            sync_payload, sync_needed_flag = self._build_sync_payload(
                remote_commands, cmd_scope, local_cmds_json, delete_cmds
            )

            if sync_needed_flag or (delete_cmds and len(sync_payload) < len(remote_commands)):
                await self._sync_commands_with_discord(sync_payload, cmd_scope)
            else:
                self.logger.debug(f"{cmd_scope} is already up-to-date with {len(remote_commands)} commands.")

        except Forbidden as e:
            raise InteractionMissingAccess(cmd_scope) from e
        except HTTPException as e:
            self._raise_sync_exception(e, local_cmds_json, cmd_scope)

    async def get_remote_commands(self, cmd_scope: "Snowflake_Type") -> List[Dict[str, Any]]:
        """
        Get the remote commands for a scope.

        Args:
            cmd_scope: The scope to get the commands for.

        """
        try:
            return await self.http.get_application_commands(self.app.id, cmd_scope)
        except Forbidden:
            self.logger.warning(f"Bot is lacking `application.commands` scope in {cmd_scope}!")
            return []

    def _build_sync_payload(
        self,
        remote_commands: List[Dict[str, Any]],
        cmd_scope: "Snowflake_Type",
        local_cmds_json: Dict["Snowflake_Type", List[Dict[str, Any]]],
        delete_cmds: bool,
    ) -> Tuple[List[Dict[str, Any]], bool]:
        """
        Build the sync payload for a single scope.

        Args:
            remote_commands: The remote commands.
            cmd_scope: The scope to sync.
            local_cmds_json: The local commands in json format.
            delete_cmds: Whether to delete commands.

        """
        sync_payload = []
        sync_needed_flag = False

        for local_cmd in self.interactions_by_scope.get(cmd_scope, {}).values():
            remote_cmd_json = next(
                (c for c in remote_commands if int(c["id"]) == int(local_cmd.cmd_id.get(cmd_scope, 0))), None
            )
            local_cmd_json = next((c for c in local_cmds_json[cmd_scope] if c["name"] == str(local_cmd.name)))

            if sync_needed(local_cmd_json, remote_cmd_json):
                sync_needed_flag = True
                sync_payload.append(local_cmd_json)
            elif not delete_cmds and remote_cmd_json:
                _remote_payload = {
                    k: v for k, v in remote_cmd_json.items() if k not in ("id", "application_id", "version")
                }
                sync_payload.append(_remote_payload)
            elif delete_cmds:
                sync_payload.append(local_cmd_json)

        sync_payload = [FastJson.loads(_dump) for _dump in {FastJson.dumps(_cmd) for _cmd in sync_payload}]
        return sync_payload, sync_needed_flag

    async def _sync_commands_with_discord(
        self, sync_payload: List[Dict[str, Any]], cmd_scope: "Snowflake_Type"
    ) -> None:
        """
        Sync the commands with discord.

        Args:
            sync_payload: The sync payload.
            cmd_scope: The scope to sync.

        """
        self.logger.info(f"Overwriting {cmd_scope} with {len(sync_payload)} application commands")
        sync_response: list[dict] = await self.http.overwrite_application_commands(self.app.id, sync_payload, cmd_scope)
        self._cache_sync_response(sync_response, cmd_scope)

    def get_application_cmd_by_id(
        self, cmd_id: "Snowflake_Type", *, scope: "Snowflake_Type" = None
    ) -> Optional[InteractionCommand]:
        """
        Get a application command from the internal cache by its ID.

        Args:
            cmd_id: The ID of the command
            scope: Optionally specify a scope to search in

        Returns:
            The command, if one with the given ID exists internally, otherwise None

        """
        cmd_id = to_snowflake(cmd_id)
        scope = to_snowflake(scope) if scope is not None else None

        if scope is not None:
            return next(
                (cmd for cmd in self.interactions_by_scope[scope].values() if cmd.get_cmd_id(scope) == cmd_id), None
            )
        return next(cmd for cmd in self._interaction_lookup.values() if cmd_id in cmd.cmd_id.values())

    def _raise_sync_exception(self, e: HTTPException, cmds_json: dict, cmd_scope: "Snowflake_Type") -> NoReturn:
        try:
            if isinstance(e.errors, dict):
                for cmd_num in e.errors.keys():
                    cmd = cmds_json[cmd_scope][int(cmd_num)]
                    output = e.search_for_message(e.errors[cmd_num], cmd)
                    if len(output) > 1:
                        output = "\n".join(output)
                        self.logger.error(f"Multiple Errors found in command `{cmd['name']}`:\n{output}")
                    else:
                        self.logger.error(f"Error in command `{cmd['name']}`: {output[0]}")
            else:
                raise e from None
        except Exception:
            # the above shouldn't fail, but if it does, just raise the exception normally
            raise e from None

    def _cache_sync_response(self, sync_response: list[dict], scope: "Snowflake_Type") -> None:
        for cmd_data in sync_response:
            command_id = Snowflake(cmd_data["id"])
            tier_0_name = cmd_data["name"]
            options = cmd_data.get("options", [])

            if any(option["type"] in (OptionType.SUB_COMMAND, OptionType.SUB_COMMAND_GROUP) for option in options):
                for option in options:
                    option_type = option["type"]

                    if option_type in (OptionType.SUB_COMMAND, OptionType.SUB_COMMAND_GROUP):
                        tier_2_name = f"{tier_0_name} {option['name']}"

                        if option_type == OptionType.SUB_COMMAND_GROUP:
                            for sub_option in option.get("options", []):
                                tier_3_name = f"{tier_2_name} {sub_option['name']}"
                                self.update_command_cache(scope, tier_3_name, command_id)
                        else:
                            self.update_command_cache(scope, tier_2_name, command_id)

            else:
                self.update_command_cache(scope, tier_0_name, command_id)

    def update_command_cache(self, scope: "Snowflake_Type", command_name: str, command_id: "Snowflake") -> None:
        """
        Update the internal cache with a command ID.

        Args:
            scope: The scope of the command to update
            command_name: The name of the command
            command_id: The ID of the command

        """
        if command := self.interactions_by_scope[scope].get(command_name):
            command.cmd_id[scope] = command_id
            self._interaction_lookup[command.resolved_name] = command

    async def get_context(self, data: dict) -> InteractionContext:
        match data["type"]:
            case InteractionType.MESSAGE_COMPONENT:
                cls = self.component_context.from_dict(self, data)
            case InteractionType.AUTOCOMPLETE:
                cls = self.autocomplete_context.from_dict(self, data)
            case InteractionType.MODAL_RESPONSE:
                cls = self.modal_context.from_dict(self, data)
            case InteractionType.APPLICATION_COMMAND:
                if data["data"].get("target_id"):
                    cls = self.context_menu_context.from_dict(self, data)
                else:
                    cls = self.slash_context.from_dict(self, data)
            case _:
                self.logger.warning(f"Unknown interaction type [{data['type']}] - please update or report this.")
                cls = self.interaction_context.from_dict(self, data)
        if not cls.channel:
            # fallback channel if not provided
            try:
                if cls.guild_id:
                    channel = await self.cache.fetch_channel(data["channel_id"])
                else:
                    channel = await self.cache.fetch_dm_channel(cls.author_id)
                cls.channel_id = channel.id
            except Forbidden:
                self.logger.debug(f"Failed to fetch channel data for {data['channel_id']}")
        return cls

    async def handle_pre_ready_response(self, data: dict) -> None:
        """
        Respond to an interaction that was received before the bot was ready.

        Args:
            data: The interaction data

        """
        if data["type"] == InteractionType.AUTOCOMPLETE:
            # we do not want to respond to autocompletes as discord will cache the response,
            # so we just ignore them
            return

        with contextlib.suppress(HTTPException):
            await self.http.post_initial_response(
                {
                    "type": CallbackType.CHANNEL_MESSAGE_WITH_SOURCE,
                    "data": {
                        "content": f"{self.user.display_name} is starting up. Please try again in a few seconds",
                        "flags": MessageFlags.EPHEMERAL,
                    },
                },
                token=data["token"],
                interaction_id=data["id"],
            )

    async def _run_slash_command(self, command: SlashCommand, ctx: "InteractionContext") -> Any:
        """Overrideable method that executes slash commands, can be used to wrap callback execution"""
        return await command(ctx, **ctx.kwargs)

    @processors.Processor.define("raw_interaction_create")
    async def _dispatch_interaction(self, event: RawGatewayEvent) -> None:  # noqa: C901
        """
        Identify and dispatch interaction of slash commands or components.

        Args:
            raw interaction event

        """
        interaction_data = event.data

        if not self._startup:
            self.logger.warning("Received interaction before startup completed, ignoring")
            if self.send_not_ready_messages:
                await self.handle_pre_ready_response(interaction_data)
            return

        if interaction_data["type"] in (
            InteractionType.APPLICATION_COMMAND,
            InteractionType.AUTOCOMPLETE,
        ):
            interaction_id = interaction_data["data"]["id"]
            name = interaction_data["data"]["name"]

            ctx = await self.get_context(interaction_data)
            if ctx.command:
                self.logger.debug(f"{ctx.command_id}::{ctx.command.name} should be called")

                if ctx.command.auto_defer:
                    auto_defer = ctx.command.auto_defer
                elif ctx.command.extension and ctx.command.extension.auto_defer:
                    auto_defer = ctx.command.extension.auto_defer
                else:
                    auto_defer = self.auto_defer

                if auto_opt := getattr(ctx, "focussed_option", None):
                    if autocomplete := ctx.command.autocomplete_callbacks.get(str(auto_opt.name)):
                        if ctx.command.has_binding:
                            callback = functools.partial(ctx.command.call_with_binding, autocomplete)
                        else:
                            callback = autocomplete
                    elif autocomplete := self._global_autocompletes.get(str(auto_opt.name)):
                        callback = autocomplete
                    else:
                        raise ValueError(f"Autocomplete callback for {auto_opt.name!s} not found")

                    await self.__dispatch_interaction(
                        ctx=ctx,
                        callback=callback(ctx),
                        callback_kwargs=ctx.kwargs,
                        error_callback=events.AutocompleteError,
                        completion_callback=events.AutocompleteCompletion,
                    )
                else:
                    await auto_defer(ctx)
                    await self.__dispatch_interaction(
                        ctx=ctx,
                        callback=self._run_slash_command(ctx.command, ctx),
                        callback_kwargs=ctx.kwargs,
                        error_callback=events.CommandError,
                        completion_callback=events.CommandCompletion,
                    )
            else:
                self.logger.error(f"Unknown cmd_id received:: {interaction_id} ({name})")

        elif interaction_data["type"] == InteractionType.MESSAGE_COMPONENT:
            # Buttons, Selects, ContextMenu::Message
            ctx = await self.get_context(interaction_data)
            component_type = interaction_data["data"]["component_type"]

            self.dispatch(events.Component(ctx=ctx))
            component_callback = self._component_callbacks.get(ctx.custom_id)
            if not component_callback:
                # evaluate regex component callbacks
                for regex, callback in self._regex_component_callbacks.items():
                    if regex.match(ctx.custom_id):
                        component_callback = callback
                        break

            if component_callback:
                await self.__dispatch_interaction(
                    ctx=ctx,
                    callback=component_callback(ctx),
                    error_callback=events.ComponentError,
                    completion_callback=events.ComponentCompletion,
                )

            if component_type == ComponentType.BUTTON:
                self.dispatch(events.ButtonPressed(ctx))

            if component_type == ComponentType.STRING_SELECT:
                self.dispatch(events.Select(ctx))

        elif interaction_data["type"] == InteractionType.MODAL_RESPONSE:
            ctx = await self.get_context(interaction_data)
            self.dispatch(events.ModalCompletion(ctx=ctx))

            modal_callback = self._modal_callbacks.get(ctx.custom_id)
            if not modal_callback:
                # evaluate regex component callbacks
                for regex, callback in self._regex_modal_callbacks.items():
                    if regex.match(ctx.custom_id):
                        modal_callback = callback
                        break

            if modal_callback:
                await self.__dispatch_interaction(
                    ctx=ctx, callback=modal_callback(ctx), error_callback=events.ModalError
                )

        else:
            raise NotImplementedError(f"Unknown Interaction Received: {interaction_data['type']}")

    # todo add typing once context is re-implemented
    async def __dispatch_interaction(
        self,
        ctx,
        callback: Coroutine,
        error_callback: Type[BaseEvent],
        completion_callback: Type[BaseEvent] | None = None,
        callback_kwargs: dict | None = None,
    ) -> None:
        if callback_kwargs is None:
            callback_kwargs = {}

        try:
            if self.pre_run_callback:
                await self.pre_run_callback(ctx, **callback_kwargs)

            # allow interactions to be responded by returning a string or an embed
            response = await callback
            if not getattr(ctx, "responded", True) and response:
                if isinstance(response, Embed) or (
                    isinstance(response, list) and all(isinstance(item, Embed) for item in response)
                ):
                    await ctx.send(embeds=response)
                else:
                    if not isinstance(response, str):
                        self.logger.warning(
                            "Command callback returned non-string value - casting to string and sending"
                        )
                    await ctx.send(str(response))

            if self.post_run_callback:
                _ = asyncio.create_task(self.post_run_callback(ctx, **callback_kwargs))  # noqa: RUF006
        except Exception as e:
            self.dispatch(error_callback(ctx=ctx, error=e))
        finally:
            if completion_callback:
                self.dispatch(completion_callback(ctx=ctx))

    @Listener.create("disconnect", is_default_listener=True)
    async def _disconnect(self) -> None:
        self._ready.clear()

    def get_extensions(self, name: str) -> list[Extension]:
        """
        Get all ext with a name or extension name.

        Args:
            name: The name of the extension, or the name of it's extension

        Returns:
            List of Extensions

        """
        if name not in self.ext.keys():
            return [ext for ext in self.ext.values() if ext.extension_name == name]

        return [self.ext.get(name, None)]

    def get_ext(self, name: str) -> Extension | None:
        """
        Get a extension with a name or extension name.

        Args:
            name: The name of the extension, or the name of it's extension

        Returns:
            A extension, if found

        """
        return ext[0] if (ext := self.get_extensions(name)) else None

    def __load_module(self, module, module_name, **load_kwargs) -> None:
        """Internal method that handles loading a module."""
        try:
            if setup := getattr(module, "setup", None):
                setup(self, **load_kwargs)
            else:
                self.logger.debug("No setup function found in %s", module_name)

                found = False
                objects = {name: obj for name, obj in inspect.getmembers(module) if isinstance(obj, type)}
                for obj_name, obj in objects.items():
                    if Extension in obj.__bases__:
                        self.logger.debug(f"Found extension class {obj_name} in {module_name}: Attempting to load")
                        obj(self, **load_kwargs)
                        found = True
                if not found:
                    raise ValueError(f"{module_name} contains no Extensions")

        except ExtensionLoadException:
            raise
        except Exception as e:
            sys.modules.pop(module_name, None)
            raise ExtensionLoadException(f"Unexpected Error loading {module_name}") from e

        else:
            self.logger.debug(f"Loaded Extension: {module_name}")
            self.__modules[module_name] = module

            if self.sync_ext and self._ready.is_set():
                try:
                    asyncio.get_running_loop()
                except RuntimeError:
                    return
                _ = asyncio.create_task(self.synchronise_interactions())  # noqa: RUF006

    def load_extension(
        self,
        name: str,
        package: str | None = None,
        **load_kwargs: Any,
    ) -> None:
        """
        Load an extension with given arguments.

        Args:
            name: The name of the extension.
            package: The package the extension is in
            **load_kwargs: The auto-filled mapping of the load keyword arguments

        """
        module_name = importlib.util.resolve_name(name, package)
        if module_name in self.__modules:
            raise Exception(f"{module_name} already loaded")

        module = importlib.import_module(module_name, package)
        self.__load_module(module, module_name, **load_kwargs)

    def load_extensions(
        self,
        *packages: str,
        recursive: bool = False,
        **load_kwargs: Any,
    ) -> None:
        """
        Load multiple extensions at once.

        Removes the need of manually looping through the package
        and loading the extensions.

        Args:
            *packages: The package(s) where the extensions are located.
            recursive: Whether to load extensions from the subdirectories within the package.

        """
        if not packages:
            raise ValueError("You must specify at least one package.")

        for package in packages:
            # If recursive then include subdirectories ('**')
            # otherwise just the package specified by the user.
            pattern = os.path.join(package, "**" if recursive else "", "*.py")

            # Find all files matching the pattern, and convert slashes to dots.
            extensions = [f.replace(os.path.sep, ".").replace(".py", "") for f in glob.glob(pattern, recursive=True)]

            for ext in extensions:
                self.load_extension(ext, **load_kwargs)

    def unload_extension(
        self, name: str, package: str | None = None, force: bool = False, **unload_kwargs: Any
    ) -> None:
        """
        Unload an extension with given arguments.

        Args:
            name: The name of the extension.
            package: The package the extension is in
            force: Whether to force unload the extension - for use in reversions
            **unload_kwargs: The auto-filled mapping of the unload keyword arguments

        """
        name = importlib.util.resolve_name(name, package)
        module = self.__modules.get(name)

        if module is None and not force:
            raise ExtensionNotFound(f"No extension called {name} is loaded")

        with contextlib.suppress(AttributeError):
            teardown = module.teardown
            teardown(**unload_kwargs)

        for ext in self.get_extensions(name):
            ext.drop(**unload_kwargs)

        sys.modules.pop(name, None)
        self.__modules.pop(name, None)

        if self.sync_ext and self._ready.is_set():
            try:
                asyncio.get_running_loop()
            except RuntimeError:
                return
            _ = asyncio.create_task(self.synchronise_interactions())  # noqa: RUF006

    def reload_extension(
        self,
        name: str,
        package: str | None = None,
        *,
        load_kwargs: Any = None,
        unload_kwargs: Any = None,
    ) -> None:
        """
        Helper method to reload an extension. Simply unloads, then loads the extension with given arguments.

        Args:
            name: The name of the extension.
            package: The package the extension is in
            load_kwargs: The manually-filled mapping of the load keyword arguments
            unload_kwargs: The manually-filled mapping of the unload keyword arguments

        """
        name = importlib.util.resolve_name(name, package)
        module = self.__modules.get(name)

        if module is None:
            self.logger.warning("Attempted to reload extension thats not loaded. Loading extension instead")
            return self.load_extension(name, package)

        backup = module

        try:
            if not load_kwargs:
                load_kwargs = {}
            if not unload_kwargs:
                unload_kwargs = {}

            self.unload_extension(name, package, **unload_kwargs)
            self.load_extension(name, package, **load_kwargs)
        except Exception as e:
            try:
                self.logger.error(f"Error reloading extension {name}: {e} - attempting to revert to previous state")
                try:
                    self.unload_extension(name, package, force=True, **unload_kwargs)  # make sure no remnants are left
                except Exception as t:
                    self.logger.debug(f"Suppressing error unloading extension {name} during reload revert: {t}")

                sys.modules[name] = backup
                self.__load_module(backup, name, **load_kwargs)
                self.logger.info(f"Reverted extension {name} to previous state ", exc_info=e)
            except Exception as ex:
                sys.modules.pop(name, None)
                raise ex from e

    async def fetch_guild(self, guild_id: "Snowflake_Type", *, force: bool = False) -> Optional[Guild]:
        """
        Fetch a guild.

        !!! note
            This method is an alias for the cache which will either return a cached object, or query discord for the object
            if its not already cached.

        Args:
            guild_id: The ID of the guild to get
            force: Whether to poll the API regardless of cache

        Returns:
            Guild Object if found, otherwise None

        """
        try:
            return await self.cache.fetch_guild(guild_id, force=force)
        except NotFound:
            return None

    def get_guild(self, guild_id: "Snowflake_Type") -> Optional[Guild]:
        """
        Get a guild.

        !!! note
            This method is an alias for the cache which will return a cached object.

        Args:
            guild_id: The ID of the guild to get

        Returns:
            Guild Object if found, otherwise None

        """
        return self.cache.get_guild(guild_id)

    async def create_guild_from_template(
        self,
        template_code: Union["GuildTemplate", str],
        name: str,
        icon: Absent[UPLOADABLE_TYPE] = MISSING,
    ) -> Optional[Guild]:
        """
        Creates a new guild based on a template.

        !!! note
            This endpoint can only be used by bots in less than 10 guilds.

        Args:
            template_code: The code of the template to use.
            name: The name of the guild (2-100 characters)
            icon: Location or File of icon to set

        Returns:
            The newly created guild object

        """
        if isinstance(template_code, GuildTemplate):
            template_code = template_code.code

        if icon:
            icon = to_image_data(icon)
        guild_data = await self.http.create_guild_from_guild_template(template_code, name, icon)
        return Guild.from_dict(guild_data, self)

    async def fetch_channel(self, channel_id: "Snowflake_Type", *, force: bool = False) -> Optional["TYPE_ALL_CHANNEL"]:
        """
        Fetch a channel.

        !!! note
            This method is an alias for the cache which will either return a cached object, or query discord for the object
            if its not already cached.

        Args:
            channel_id: The ID of the channel to get
            force: Whether to poll the API regardless of cache

        Returns:
            Channel Object if found, otherwise None

        """
        try:
            return await self.cache.fetch_channel(channel_id, force=force)
        except NotFound:
            return None

    def get_channel(self, channel_id: "Snowflake_Type") -> Optional["TYPE_ALL_CHANNEL"]:
        """
        Get a channel.

        !!! note
            This method is an alias for the cache which will return a cached object.

        Args:
            channel_id: The ID of the channel to get

        Returns:
            Channel Object if found, otherwise None

        """
        return self.cache.get_channel(channel_id)

    async def fetch_user(self, user_id: "Snowflake_Type", *, force: bool = False) -> Optional[User]:
        """
        Fetch a user.

        !!! note
            This method is an alias for the cache which will either return a cached object, or query discord for the object
            if its not already cached.

        Args:
            user_id: The ID of the user to get
            force: Whether to poll the API regardless of cache

        Returns:
            User Object if found, otherwise None

        """
        try:
            return await self.cache.fetch_user(user_id, force=force)
        except NotFound:
            return None

    def get_user(self, user_id: "Snowflake_Type") -> Optional[User]:
        """
        Get a user.

        !!! note
            This method is an alias for the cache which will return a cached object.

        Args:
            user_id: The ID of the user to get

        Returns:
            User Object if found, otherwise None

        """
        return self.cache.get_user(user_id)

    async def fetch_member(
        self, user_id: "Snowflake_Type", guild_id: "Snowflake_Type", *, force: bool = False
    ) -> Optional[Member]:
        """
        Fetch a member from a guild.

        !!! note
            This method is an alias for the cache which will either return a cached object, or query discord for the object
            if its not already cached.

        Args:
            user_id: The ID of the member
            guild_id: The ID of the guild to get the member from
            force: Whether to poll the API regardless of cache

        Returns:
            Member object if found, otherwise None

        """
        try:
            return await self.cache.fetch_member(guild_id, user_id, force=force)
        except NotFound:
            return None

    def get_member(self, user_id: "Snowflake_Type", guild_id: "Snowflake_Type") -> Optional[Member]:
        """
        Get a member from a guild.

        !!! note
            This method is an alias for the cache which will return a cached object.

        Args:
            user_id: The ID of the member
            guild_id: The ID of the guild to get the member from

        Returns:
            Member object if found, otherwise None

        """
        return self.cache.get_member(guild_id, user_id)

    async def fetch_scheduled_event(
        self,
        guild_id: "Snowflake_Type",
        scheduled_event_id: "Snowflake_Type",
        with_user_count: bool = False,
    ) -> Optional["ScheduledEvent"]:
        """
        Fetch a scheduled event by id.

        Args:
            guild_id: The ID of the guild to get the scheduled event from
            scheduled_event_id: The ID of the scheduled event to get
            with_user_count: Whether to include the user count in the response

        Returns:
            The scheduled event if found, otherwise None

        """
        try:
            scheduled_event_data = await self.http.get_scheduled_event(guild_id, scheduled_event_id, with_user_count)
            return self.cache.place_scheduled_event_data(scheduled_event_data)
        except NotFound:
            return None

    def get_scheduled_event(
        self,
        scheduled_event_id: "Snowflake_Type",
    ) -> Optional["ScheduledEvent"]:
        """
        Get a scheduled event by id.

        !!! note
            This method is an alias for the cache which will return a cached object.

        Args:
            scheduled_event_id: The ID of the scheduled event to get

        Returns:
            The scheduled event if found, otherwise None

        """
        return self.cache.get_scheduled_event(scheduled_event_id)

    async def fetch_custom_emoji(
        self, emoji_id: "Snowflake_Type", guild_id: "Snowflake_Type", *, force: bool = False
    ) -> Optional[CustomEmoji]:
        """
        Fetch a custom emoji by id.

        Args:
            emoji_id: The id of the custom emoji.
            guild_id: The id of the guild the emoji belongs to.
            force: Whether to poll the API regardless of cache.

        Returns:
            The custom emoji if found, otherwise None.

        """
        try:
            return await self.cache.fetch_emoji(guild_id, emoji_id, force=force)
        except NotFound:
            return None

    def get_custom_emoji(
        self, emoji_id: "Snowflake_Type", guild_id: Optional["Snowflake_Type"] = None
    ) -> Optional[CustomEmoji]:
        """
        Get a custom emoji by id.

        Args:
            emoji_id: The id of the custom emoji.
            guild_id: The id of the guild the emoji belongs to.

        Returns:
            The custom emoji if found, otherwise None.

        """
        emoji = self.cache.get_emoji(emoji_id)
        if emoji and (not guild_id or emoji._guild_id == to_snowflake(guild_id)):
            return emoji
        return None

    async def fetch_sticker(self, sticker_id: "Snowflake_Type") -> Optional[Sticker]:
        """
        Fetch a sticker by ID.

        Args:
            sticker_id: The ID of the sticker.

        Returns:
            A sticker object if found, otherwise None

        """
        try:
            sticker_data = await self.http.get_sticker(sticker_id)
            return Sticker.from_dict(sticker_data, self)
        except NotFound:
            return None

    async def fetch_nitro_packs(self) -> Optional[List["StickerPack"]]:
        """
        List the sticker packs available to Nitro subscribers.

        Returns:
            A list of StickerPack objects if found, otherwise returns None

        """
        try:
            packs_data = await self.http.list_nitro_sticker_packs()
            return [StickerPack.from_dict(data, self) for data in packs_data]

        except NotFound:
            return None

    async def fetch_voice_regions(self) -> List["VoiceRegion"]:
        """
        List the voice regions available on Discord.

        Returns:
            A list of voice regions.

        """
        regions_data = await self.http.list_voice_regions()
        return VoiceRegion.from_list(regions_data)

    async def connect_to_vc(
        self,
        guild_id: "Snowflake_Type",
        channel_id: "Snowflake_Type",
        muted: bool = False,
        deafened: bool = False,
    ) -> ActiveVoiceState:
        """
        Connect the bot to a voice channel.

        Args:
            guild_id: id of the guild the voice channel is in.
            channel_id: id of the voice channel client wants to join.
            muted: Whether the bot should be muted when connected.
            deafened: Whether the bot should be deafened when connected.

        Returns:
            The new active voice state on successfully connection.

        """
        return await self._connection_state.voice_connect(guild_id, channel_id, muted, deafened)

    def get_bot_voice_state(self, guild_id: "Snowflake_Type") -> Optional[ActiveVoiceState]:
        """
        Get the bot's voice state for a guild.

        Args:
            guild_id: The target guild's id.

        Returns:
            The bot's voice state for the guild if connected, otherwise None.

        """
        return self._connection_state.get_voice_state(guild_id)

    async def fetch_entitlements(
        self,
        *,
        user_id: "Optional[Snowflake_Type]" = None,
        sku_ids: "Optional[list[Snowflake_Type]]" = None,
        before: "Optional[Snowflake_Type]" = None,
        after: "Optional[Snowflake_Type]" = None,
        limit: Optional[int] = 100,
        guild_id: "Optional[Snowflake_Type]" = None,
        exclude_ended: Optional[bool] = None,
    ) -> List[Entitlement]:
        """
        Fetch the entitlements for the bot's application.

        Args:
            user_id: The ID of the user to filter entitlements by.
            sku_ids: The IDs of the SKUs to filter entitlements by.
            before: Get entitlements before this ID.
            after: Get entitlements after this ID.
            limit: The maximum number of entitlements to return. Maximum is 100.
            guild_id: The ID of the guild to filter entitlements by.
            exclude_ended: Whether to exclude ended entitlements.

        Returns:
            A list of entitlements.

        """
        entitlements_data = await self.http.get_entitlements(
            self.app.id,
            user_id=user_id,
            sku_ids=sku_ids,
            before=before,
            after=after,
            limit=limit,
            guild_id=guild_id,
            exclude_ended=exclude_ended,
        )
        return Entitlement.from_list(entitlements_data, self)

    async def create_test_entitlement(
        self, sku_id: "Snowflake_Type", owner_id: "Snowflake_Type", owner_type: int
    ) -> Entitlement:
        """
        Create a test entitlement for the bot's application.

        Args:
            sku_id: The ID of the SKU to create the entitlement for.
            owner_id: The ID of the owner of the entitlement.
            owner_type: The type of the owner of the entitlement. 1 for a guild subscription, 2 for a user subscription

        Returns:
            The created entitlement.

        """
        payload = {"sku_id": to_snowflake(sku_id), "owner_id": to_snowflake(owner_id), "owner_type": owner_type}

        entitlement_data = await self.http.create_test_entitlement(payload, self.app.id)
        return Entitlement.from_dict(entitlement_data, self)

    async def delete_test_entitlement(self, entitlement_id: "Snowflake_Type") -> None:
        """
        Delete a test entitlement for the bot's application.

        Args:
            entitlement_id: The ID of the entitlement to delete.

        """
        await self.http.delete_test_entitlement(self.app.id, to_snowflake(entitlement_id))

    def mention_command(self, name: str, scope: int = 0) -> str:
        """
        Returns a string that would mention the interaction specified.

        Args:
            name: The name of the interaction.
            scope: The scope of the interaction. Defaults to 0, the global scope.

        Returns:
            str: The interaction's mention in the specified scope.

        """
        return self.interactions_by_scope[scope][name].mention(scope)

    async def change_presence(
        self,
        status: Optional[Union[str, Status]] = Status.ONLINE,
        activity: Optional[Union[Activity, str]] = None,
    ) -> None:
        """
        Change the bots presence.

        Args:
            status: The status for the bot to be. i.e. online, afk, etc.
            activity: The activity for the bot to be displayed as doing.

        !!! note
            Bots may only be `playing` `streaming` `listening` `watching`  `competing` or `custom`

        """
        await self._connection_state.change_presence(status, activity)

activity: Activity property

Get the activity of the bot.

app: Application property

Returns the bots application.

application_commands: List[InteractionCommand] property

A list of all application commands registered within the bot.

async_startup_tasks: list[tuple[Callable[..., Coroutine], Iterable[Any], dict[str, Any]]] = [] instance-attribute

A list of coroutines to run during startup

auto_defer = auto_defer instance-attribute

A system to automatically defer commands after a set duration

autocomplete_context: Type[BaseContext] = autocomplete_context instance-attribute

The object to instantiate for Autocomplete Context

average_latency: float property

Returns the average latency of the websocket connection (seconds).

component_context: Type[BaseContext] = component_context instance-attribute

The object to instantiate for Component Context

context_menu_context: Type[BaseContext] = context_menu_context instance-attribute

The object to instantiate for Context Menu Context

debug_scope = to_snowflake(debug_scope) if debug_scope is not MISSING else MISSING instance-attribute

Sync global commands as guild for quicker command updates during debug

del_unused_app_cmd: bool = delete_unused_application_cmds instance-attribute

Should unused application commands be deleted?

ext: Dict[str, Extension] = {} instance-attribute

A dictionary of mounted ext

fetch_members = fetch_members instance-attribute

Fetch the full members list of all guilds on startup

gateway_started: bool property

Returns if the gateway has been started.

guild_event_timeout = 3 instance-attribute

How long to wait for guilds to be cached

guilds: List[Guild] property

Returns a list of all guilds the bot is in.

http: HTTPClient = HTTPClient(logger=self.logger, show_ratelimit_tracebacks=show_ratelimit_tracebacks, proxy=proxy) instance-attribute

The HTTP client to use when interacting with discord endpoints

interaction_context: Type[BaseContext] = interaction_context instance-attribute

The object to instantiate for Interaction Context

interaction_tree: Dict[Snowflake_Type, Dict[str, InteractionCommand | Dict[str, InteractionCommand]]] = {} instance-attribute

A dictionary of registered application commands in a tree

interactions_by_scope: Dict[Snowflake_Type, Dict[str, InteractionCommand]] = {} instance-attribute

A dictionary of registered application commands: {scope: [commands]}

is_closed: bool property

Returns True if the bot has closed.

is_ready: bool property

Returns True if the bot is ready.

latency: float property

Returns the latency of the websocket connection (seconds).

logger = logger instance-attribute

The logger interactions.py should use. Do not use in combination with Client.basic_logging and Client.logging_level.

Note

Different loggers with multiple clients are not supported

modal_context: Type[BaseContext] = modal_context instance-attribute

The object to instantiate for Modal Context

owner: Optional[User] property

Returns the bot's owner'.

owners: List[User] property

Returns the bot's owners as declared via client.owner_ids.

send_command_tracebacks: bool = send_command_tracebacks instance-attribute

Should the traceback of command errors be sent in reply to the command invocation

send_not_ready_messages: bool = send_not_ready_messages instance-attribute

Should the bot send a message when it is not ready yet in response to a command invocation

slash_context: Type[BaseContext] = slash_context instance-attribute

The object to instantiate for Slash Context

start_time: datetime property

The start time of the bot.

status: Status property

Get the status of the bot.

IE online, afk, dnd

sync_ext: bool = sync_ext instance-attribute

Should we sync whenever a extension is (un)loaded

sync_interactions: bool = sync_interactions instance-attribute

Should application commands be synced

user: ClientUser property

Returns the bot's user.

ws: GatewayClient property

Returns the websocket client.

__load_module(module, module_name, **load_kwargs)

Internal method that handles loading a module.

Source code in interactions/client/client.py
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
def __load_module(self, module, module_name, **load_kwargs) -> None:
    """Internal method that handles loading a module."""
    try:
        if setup := getattr(module, "setup", None):
            setup(self, **load_kwargs)
        else:
            self.logger.debug("No setup function found in %s", module_name)

            found = False
            objects = {name: obj for name, obj in inspect.getmembers(module) if isinstance(obj, type)}
            for obj_name, obj in objects.items():
                if Extension in obj.__bases__:
                    self.logger.debug(f"Found extension class {obj_name} in {module_name}: Attempting to load")
                    obj(self, **load_kwargs)
                    found = True
            if not found:
                raise ValueError(f"{module_name} contains no Extensions")

    except ExtensionLoadException:
        raise
    except Exception as e:
        sys.modules.pop(module_name, None)
        raise ExtensionLoadException(f"Unexpected Error loading {module_name}") from e

    else:
        self.logger.debug(f"Loaded Extension: {module_name}")
        self.__modules[module_name] = module

        if self.sync_ext and self._ready.is_set():
            try:
                asyncio.get_running_loop()
            except RuntimeError:
                return
            _ = asyncio.create_task(self.synchronise_interactions())  # noqa: RUF006

add_command(func)

Add a command to the client.

Parameters:

Name Type Description Default
func Callable

The command to add

required
Source code in interactions/client/client.py
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
def add_command(self, func: Callable) -> None:
    """
    Add a command to the client.

    Args:
        func: The command to add

    """
    if isinstance(func, ModalCommand):
        self.add_modal_callback(func)
    elif isinstance(func, ComponentCommand):
        self.add_component_callback(func)
    elif isinstance(func, InteractionCommand):
        self.add_interaction(func)
    elif isinstance(func, Listener):
        self.add_listener(func)
    elif isinstance(func, GlobalAutoComplete):
        self.add_global_autocomplete(func)
    elif not isinstance(func, BaseCommand):
        raise TypeError("Invalid command type")

    if not func.callback:
        # for group = SlashCommand(...) usage
        return

    if isinstance(func.callback, functools.partial):
        ext = getattr(func, "extension", None)
        self.logger.debug(f"Added callback: {f'{ext.name}.' if ext else ''}{func.callback.func.__name__}")
    else:
        self.logger.debug(f"Added callback: {func.callback.__name__}")

    for hook in self._add_command_hook:
        hook(func)

    self.dispatch(CallbackAdded(callback=func, extension=func.extension if hasattr(func, "extension") else None))

add_component_callback(command)

Add a component callback to the client.

Parameters:

Name Type Description Default
command ComponentCommand

The command to add

required
Source code in interactions/client/client.py
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
def add_component_callback(self, command: ComponentCommand) -> None:
    """
    Add a component callback to the client.

    Args:
        command: The command to add

    """
    for listener in command.listeners:
        if isinstance(listener, re.Pattern):
            if listener in self._regex_component_callbacks.keys():
                raise ValueError(f"Duplicate Component! Multiple component callbacks for `{listener}`")
            self._regex_component_callbacks[listener] = command
        else:
            # I know this isn't an ideal solution, but it means we can lookup callbacks with O(1)
            if listener in self._component_callbacks.keys():
                raise ValueError(f"Duplicate Component! Multiple component callbacks for `{listener}`")
            self._component_callbacks[listener] = command
        continue

add_event_processor(event_name=MISSING)

A decorator to be used to add event processors.

Parameters:

Name Type Description Default
event_name Absent[str]

The event name to use, if not the coroutine name

MISSING

Returns:

Type Description
Callable[[AsyncCallable], AsyncCallable]

A function that can be used to hook into the event.

Source code in interactions/client/client.py
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
def add_event_processor(self, event_name: Absent[str] = MISSING) -> Callable[[AsyncCallable], AsyncCallable]:
    """
    A decorator to be used to add event processors.

    Args:
        event_name: The event name to use, if not the coroutine name

    Returns:
        A function that can be used to hook into the event.

    """

    def wrapper(coro: AsyncCallable) -> AsyncCallable:
        name = event_name
        if name is MISSING:
            name = coro.__name__
        name = name.lstrip("_")
        name = name.removeprefix("on_")
        self.processors[name] = coro
        return coro

    return wrapper

add_global_autocomplete(callback)

Add a global autocomplete to the client.

Parameters:

Name Type Description Default
callback GlobalAutoComplete

The autocomplete to add

required
Source code in interactions/client/client.py
1380
1381
1382
1383
1384
1385
1386
1387
1388
def add_global_autocomplete(self, callback: GlobalAutoComplete) -> None:
    """
    Add a global autocomplete to the client.

    Args:
        callback: The autocomplete to add

    """
    self._global_autocompletes[callback.option_name] = callback

add_interaction(command)

Add a slash command to the client.

Parameters:

Name Type Description Default
command InteractionCommand

The command to add

required
Source code in interactions/client/client.py
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
def add_interaction(self, command: InteractionCommand) -> bool:
    """
    Add a slash command to the client.

    Args:
        command InteractionCommand: The command to add

    """
    if self.debug_scope:
        command.scopes = [self.debug_scope]

    if self.disable_dm_commands:
        command.dm_permission = False

    # for SlashCommand objs without callback (like objects made to hold group info etc)
    if command.callback is None:
        return False

    if isinstance(command, SlashCommand):
        command._parse_parameters()

    base, group, sub, *_ = [*command.resolved_name.split(" "), None, None]

    for scope in command.scopes:
        if scope not in self.interactions_by_scope:
            self.interactions_by_scope[scope] = {}
        elif command.resolved_name in self.interactions_by_scope[scope]:
            old_cmd = self.interactions_by_scope[scope][command.resolved_name]
            raise ValueError(f"Duplicate Command! {scope}::{old_cmd.resolved_name}")

        # if self.enforce_interaction_perms:
        #     command.checks.append(command._permission_enforcer)

        self.interactions_by_scope[scope][command.resolved_name] = command

        if scope not in self.interaction_tree:
            self.interaction_tree[scope] = {}

        if group is None or isinstance(command, ContextMenu):
            self.interaction_tree[scope][command.resolved_name] = command
        else:
            if not (current := self.interaction_tree[scope].get(base)) or isinstance(current, SlashCommand):
                self.interaction_tree[scope][base] = {}
            if sub is None:
                self.interaction_tree[scope][base][group] = command
            else:
                if not (current := self.interaction_tree[scope][base].get(group)) or isinstance(
                    current, SlashCommand
                ):
                    self.interaction_tree[scope][base][group] = {}
                self.interaction_tree[scope][base][group][sub] = command

    return True

add_listener(listener)

Add a listener for an event, if no event is passed, one is determined.

Parameters:

Name Type Description Default
listener Listener

The listener to add to the client

required
Source code in interactions/client/client.py
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
def add_listener(self, listener: Listener) -> None:
    """
    Add a listener for an event, if no event is passed, one is determined.

    Args:
        listener Listener: The listener to add to the client

    """
    if listener.event == "event":
        self.logger.critical(
            f"Subscribing to `{listener.event}` - Meta Events are very expensive; remember to remove it before"
            " releasing your bot"
        )

    if not listener.is_default_listener:
        # check that the required intents are enabled

        event_class_name = "".join([name.capitalize() for name in listener.event.split("_")])
        if event_class := globals().get(event_class_name):
            if required_intents := _INTENT_EVENTS.get(event_class):
                if all(required_intent not in self.intents for required_intent in required_intents):
                    self.logger.warning(
                        f"Event `{listener.event}` will not work since the required intent is not set -> Requires"
                        f" any of: `{required_intents}`"
                    )

    # prevent the same callback being added twice
    if listener in self.listeners.get(listener.event, []):
        self.logger.debug(f"Listener {listener} has already been hooked, not re-hooking it again")
        return

    listener.lazy_parse_params()

    if listener.event not in self.listeners:
        self.listeners[listener.event] = []
    self.listeners[listener.event].append(listener)

    # check if other listeners are to be deleted
    default_listeners = [c_listener.is_default_listener for c_listener in self.listeners[listener.event]]
    removes_defaults = [c_listener.disable_default_listeners for c_listener in self.listeners[listener.event]]

    if any(default_listeners) and any(removes_defaults):
        self.listeners[listener.event] = [
            c_listener for c_listener in self.listeners[listener.event] if not c_listener.is_default_listener
        ]

add_modal_callback(command)

Add a modal callback to the client.

Parameters:

Name Type Description Default
command ModalCommand

The command to add

required
Source code in interactions/client/client.py
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
def add_modal_callback(self, command: ModalCommand) -> None:
    """
    Add a modal callback to the client.

    Args:
        command: The command to add

    """
    # test for parameters that arent the ctx (or self)
    if command.has_binding:
        callback = functools.partial(command.callback, None, None)
    else:
        callback = functools.partial(command.callback, None)

    if not inspect.signature(callback).parameters:
        # if there are none, notify the command to just pass the ctx and not kwargs
        # TODO: just make modal callbacks not pass kwargs at all (breaking)
        command._just_ctx = True

    for listener in command.listeners:
        if isinstance(listener, re.Pattern):
            if listener in self._regex_component_callbacks.keys():
                raise ValueError(f"Duplicate Component! Multiple modal callbacks for `{listener}`")
            self._regex_modal_callbacks[listener] = command
        else:
            if listener in self._modal_callbacks.keys():
                raise ValueError(f"Duplicate Component! Multiple modal callbacks for `{listener}`")
            self._modal_callbacks[listener] = command
        continue

astart(token=None) async

Asynchronous method to start the bot.

Parameters:

Name Type Description Default
token str | None

Your bot's token

None
Source code in interactions/client/client.py
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
async def astart(self, token: str | None = None) -> None:
    """
    Asynchronous method to start the bot.

    Args:
        token: Your bot's token

    """
    await self.login(token)

    # run any pending startup tasks
    if self.async_startup_tasks:
        try:
            await asyncio.gather(
                *[
                    task[0](*task[1] if len(task) > 1 else [], **task[2] if len(task) == 3 else {})
                    for task in self.async_startup_tasks
                ]
            )
        except Exception as e:
            self.dispatch(events.Error(source="async-extension-loader", error=e))
    try:
        await self._connection_state.start()
    finally:
        await self.stop()

change_presence(status=Status.ONLINE, activity=None) async

Change the bots presence.

Parameters:

Name Type Description Default
status Optional[Union[str, Status]]

The status for the bot to be. i.e. online, afk, etc.

Status.ONLINE
activity Optional[Union[Activity, str]]

The activity for the bot to be displayed as doing.

None

Note

Bots may only be playing streaming listening watching competing or custom

Source code in interactions/client/client.py
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
async def change_presence(
    self,
    status: Optional[Union[str, Status]] = Status.ONLINE,
    activity: Optional[Union[Activity, str]] = None,
) -> None:
    """
    Change the bots presence.

    Args:
        status: The status for the bot to be. i.e. online, afk, etc.
        activity: The activity for the bot to be displayed as doing.

    !!! note
        Bots may only be `playing` `streaming` `listening` `watching`  `competing` or `custom`

    """
    await self._connection_state.change_presence(status, activity)

command(*args, **kwargs)

A decorator that registers a command. Aliases interactions.slash_command

Source code in interactions/client/client.py
1180
1181
1182
1183
1184
def command(self, *args, **kwargs) -> Callable:
    """A decorator that registers a command. Aliases `interactions.slash_command`"""
    raise NotImplementedError(
        "Use interactions.slash_command instead. Please consult the v4 -> v5 migration guide https://interactions-py.github.io/interactions.py/Guides/98%20Migration%20from%204.X/"
    )

connect_to_vc(guild_id, channel_id, muted=False, deafened=False) async

Connect the bot to a voice channel.

Parameters:

Name Type Description Default
guild_id Snowflake_Type

id of the guild the voice channel is in.

required
channel_id Snowflake_Type

id of the voice channel client wants to join.

required
muted bool

Whether the bot should be muted when connected.

False
deafened bool

Whether the bot should be deafened when connected.

False

Returns:

Type Description
ActiveVoiceState

The new active voice state on successfully connection.

Source code in interactions/client/client.py
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
async def connect_to_vc(
    self,
    guild_id: "Snowflake_Type",
    channel_id: "Snowflake_Type",
    muted: bool = False,
    deafened: bool = False,
) -> ActiveVoiceState:
    """
    Connect the bot to a voice channel.

    Args:
        guild_id: id of the guild the voice channel is in.
        channel_id: id of the voice channel client wants to join.
        muted: Whether the bot should be muted when connected.
        deafened: Whether the bot should be deafened when connected.

    Returns:
        The new active voice state on successfully connection.

    """
    return await self._connection_state.voice_connect(guild_id, channel_id, muted, deafened)

create_guild_from_template(template_code, name, icon=MISSING) async

Creates a new guild based on a template.

Note

This endpoint can only be used by bots in less than 10 guilds.

Parameters:

Name Type Description Default
template_code Union[GuildTemplate, str]

The code of the template to use.

required
name str

The name of the guild (2-100 characters)

required
icon Absent[UPLOADABLE_TYPE]

Location or File of icon to set

MISSING

Returns:

Type Description
Optional[Guild]

The newly created guild object

Source code in interactions/client/client.py
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
async def create_guild_from_template(
    self,
    template_code: Union["GuildTemplate", str],
    name: str,
    icon: Absent[UPLOADABLE_TYPE] = MISSING,
) -> Optional[Guild]:
    """
    Creates a new guild based on a template.

    !!! note
        This endpoint can only be used by bots in less than 10 guilds.

    Args:
        template_code: The code of the template to use.
        name: The name of the guild (2-100 characters)
        icon: Location or File of icon to set

    Returns:
        The newly created guild object

    """
    if isinstance(template_code, GuildTemplate):
        template_code = template_code.code

    if icon:
        icon = to_image_data(icon)
    guild_data = await self.http.create_guild_from_guild_template(template_code, name, icon)
    return Guild.from_dict(guild_data, self)

create_test_entitlement(sku_id, owner_id, owner_type) async

Create a test entitlement for the bot's application.

Parameters:

Name Type Description Default
sku_id Snowflake_Type

The ID of the SKU to create the entitlement for.

required
owner_id Snowflake_Type

The ID of the owner of the entitlement.

required
owner_type int

The type of the owner of the entitlement. 1 for a guild subscription, 2 for a user subscription

required

Returns:

Type Description
Entitlement

The created entitlement.

Source code in interactions/client/client.py
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
async def create_test_entitlement(
    self, sku_id: "Snowflake_Type", owner_id: "Snowflake_Type", owner_type: int
) -> Entitlement:
    """
    Create a test entitlement for the bot's application.

    Args:
        sku_id: The ID of the SKU to create the entitlement for.
        owner_id: The ID of the owner of the entitlement.
        owner_type: The type of the owner of the entitlement. 1 for a guild subscription, 2 for a user subscription

    Returns:
        The created entitlement.

    """
    payload = {"sku_id": to_snowflake(sku_id), "owner_id": to_snowflake(owner_id), "owner_type": owner_type}

    entitlement_data = await self.http.create_test_entitlement(payload, self.app.id)
    return Entitlement.from_dict(entitlement_data, self)

default_error_handler(source, error) staticmethod

The default error logging behaviour.

Parameters:

Name Type Description Default
source str

The source of this error

required
error BaseException

The exception itself

required
Source code in interactions/client/client.py
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
@staticmethod
def default_error_handler(source: str, error: BaseException) -> None:
    """
    The default error logging behaviour.

    Args:
        source: The source of this error
        error: The exception itself

    """
    out = traceback.format_exception(error)

    if isinstance(error, HTTPException):
        # HTTPException's are of 3 known formats, we can parse them for human readable errors
        with contextlib.suppress(Exception):
            out = [str(error)]
    get_logger().error(
        "Ignoring exception in {}:{}{}".format(source, "\n" if len(out) > 1 else " ", "".join(out)),
    )

delete_test_entitlement(entitlement_id) async

Delete a test entitlement for the bot's application.

Parameters:

Name Type Description Default
entitlement_id Snowflake_Type

The ID of the entitlement to delete.

required
Source code in interactions/client/client.py
2565
2566
2567
2568
2569
2570
2571
2572
2573
async def delete_test_entitlement(self, entitlement_id: "Snowflake_Type") -> None:
    """
    Delete a test entitlement for the bot's application.

    Args:
        entitlement_id: The ID of the entitlement to delete.

    """
    await self.http.delete_test_entitlement(self.app.id, to_snowflake(entitlement_id))

dispatch(event, *args, **kwargs)

Dispatch an event.

Parameters:

Name Type Description Default
event events.BaseEvent

The event to be dispatched.

required
Source code in interactions/client/client.py
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
def dispatch(self, event: events.BaseEvent, *args, **kwargs) -> None:
    """
    Dispatch an event.

    Args:
        event: The event to be dispatched.

    """
    if listeners := self.listeners.get(event.resolved_name, []):
        self.logger.debug(f"Dispatching Event: {event.resolved_name}")
        event.bot = self
        for _listen in listeners:
            try:
                self._queue_task(_listen, event, *args, **kwargs)
            except Exception as e:
                raise BotException(
                    f"An error occurred attempting during {event.resolved_name} event processing"
                ) from e

    try:
        asyncio.get_running_loop()
        _ = asyncio.create_task(self._process_waits(event))  # noqa: RUF006
    except RuntimeError:
        # dispatch attempt before event loop is running
        self.async_startup_tasks.append((self._process_waits, (event,), {}))

    if "event" in self.listeners:
        # special meta event listener
        for _listen in self.listeners["event"]:
            self._queue_task(_listen, event, *args, **kwargs)

fetch_channel(channel_id, *, force=False) async

Fetch a channel.

Note

This method is an alias for the cache which will either return a cached object, or query discord for the object if its not already cached.

Parameters:

Name Type Description Default
channel_id Snowflake_Type

The ID of the channel to get

required
force bool

Whether to poll the API regardless of cache

False

Returns:

Type Description
Optional[TYPE_ALL_CHANNEL]

Channel Object if found, otherwise None

Source code in interactions/client/client.py
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
async def fetch_channel(self, channel_id: "Snowflake_Type", *, force: bool = False) -> Optional["TYPE_ALL_CHANNEL"]:
    """
    Fetch a channel.

    !!! note
        This method is an alias for the cache which will either return a cached object, or query discord for the object
        if its not already cached.

    Args:
        channel_id: The ID of the channel to get
        force: Whether to poll the API regardless of cache

    Returns:
        Channel Object if found, otherwise None

    """
    try:
        return await self.cache.fetch_channel(channel_id, force=force)
    except NotFound:
        return None

fetch_custom_emoji(emoji_id, guild_id, *, force=False) async

Fetch a custom emoji by id.

Parameters:

Name Type Description Default
emoji_id Snowflake_Type

The id of the custom emoji.

required
guild_id Snowflake_Type

The id of the guild the emoji belongs to.

required
force bool

Whether to poll the API regardless of cache.

False

Returns:

Type Description
Optional[CustomEmoji]

The custom emoji if found, otherwise None.

Source code in interactions/client/client.py
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
async def fetch_custom_emoji(
    self, emoji_id: "Snowflake_Type", guild_id: "Snowflake_Type", *, force: bool = False
) -> Optional[CustomEmoji]:
    """
    Fetch a custom emoji by id.

    Args:
        emoji_id: The id of the custom emoji.
        guild_id: The id of the guild the emoji belongs to.
        force: Whether to poll the API regardless of cache.

    Returns:
        The custom emoji if found, otherwise None.

    """
    try:
        return await self.cache.fetch_emoji(guild_id, emoji_id, force=force)
    except NotFound:
        return None

fetch_entitlements(*, user_id=None, sku_ids=None, before=None, after=None, limit=100, guild_id=None, exclude_ended=None) async

Fetch the entitlements for the bot's application.

Parameters:

Name Type Description Default
user_id Optional[Snowflake_Type]

The ID of the user to filter entitlements by.

None
sku_ids Optional[list[Snowflake_Type]]

The IDs of the SKUs to filter entitlements by.

None
before Optional[Snowflake_Type]

Get entitlements before this ID.

None
after Optional[Snowflake_Type]

Get entitlements after this ID.

None
limit Optional[int]

The maximum number of entitlements to return. Maximum is 100.

100
guild_id Optional[Snowflake_Type]

The ID of the guild to filter entitlements by.

None
exclude_ended Optional[bool]

Whether to exclude ended entitlements.

None

Returns:

Type Description
List[Entitlement]

A list of entitlements.

Source code in interactions/client/client.py
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
async def fetch_entitlements(
    self,
    *,
    user_id: "Optional[Snowflake_Type]" = None,
    sku_ids: "Optional[list[Snowflake_Type]]" = None,
    before: "Optional[Snowflake_Type]" = None,
    after: "Optional[Snowflake_Type]" = None,
    limit: Optional[int] = 100,
    guild_id: "Optional[Snowflake_Type]" = None,
    exclude_ended: Optional[bool] = None,
) -> List[Entitlement]:
    """
    Fetch the entitlements for the bot's application.

    Args:
        user_id: The ID of the user to filter entitlements by.
        sku_ids: The IDs of the SKUs to filter entitlements by.
        before: Get entitlements before this ID.
        after: Get entitlements after this ID.
        limit: The maximum number of entitlements to return. Maximum is 100.
        guild_id: The ID of the guild to filter entitlements by.
        exclude_ended: Whether to exclude ended entitlements.

    Returns:
        A list of entitlements.

    """
    entitlements_data = await self.http.get_entitlements(
        self.app.id,
        user_id=user_id,
        sku_ids=sku_ids,
        before=before,
        after=after,
        limit=limit,
        guild_id=guild_id,
        exclude_ended=exclude_ended,
    )
    return Entitlement.from_list(entitlements_data, self)

fetch_guild(guild_id, *, force=False) async

Fetch a guild.

Note

This method is an alias for the cache which will either return a cached object, or query discord for the object if its not already cached.

Parameters:

Name Type Description Default
guild_id Snowflake_Type

The ID of the guild to get

required
force bool

Whether to poll the API regardless of cache

False

Returns:

Type Description
Optional[Guild]

Guild Object if found, otherwise None

Source code in interactions/client/client.py
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
async def fetch_guild(self, guild_id: "Snowflake_Type", *, force: bool = False) -> Optional[Guild]:
    """
    Fetch a guild.

    !!! note
        This method is an alias for the cache which will either return a cached object, or query discord for the object
        if its not already cached.

    Args:
        guild_id: The ID of the guild to get
        force: Whether to poll the API regardless of cache

    Returns:
        Guild Object if found, otherwise None

    """
    try:
        return await self.cache.fetch_guild(guild_id, force=force)
    except NotFound:
        return None

fetch_member(user_id, guild_id, *, force=False) async

Fetch a member from a guild.

Note

This method is an alias for the cache which will either return a cached object, or query discord for the object if its not already cached.

Parameters:

Name Type Description Default
user_id Snowflake_Type

The ID of the member

required
guild_id Snowflake_Type

The ID of the guild to get the member from

required
force bool

Whether to poll the API regardless of cache

False

Returns:

Type Description
Optional[Member]

Member object if found, otherwise None

Source code in interactions/client/client.py
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
async def fetch_member(
    self, user_id: "Snowflake_Type", guild_id: "Snowflake_Type", *, force: bool = False
) -> Optional[Member]:
    """
    Fetch a member from a guild.

    !!! note
        This method is an alias for the cache which will either return a cached object, or query discord for the object
        if its not already cached.

    Args:
        user_id: The ID of the member
        guild_id: The ID of the guild to get the member from
        force: Whether to poll the API regardless of cache

    Returns:
        Member object if found, otherwise None

    """
    try:
        return await self.cache.fetch_member(guild_id, user_id, force=force)
    except NotFound:
        return None

fetch_nitro_packs() async

List the sticker packs available to Nitro subscribers.

Returns:

Type Description
Optional[List[StickerPack]]

A list of StickerPack objects if found, otherwise returns None

Source code in interactions/client/client.py
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
async def fetch_nitro_packs(self) -> Optional[List["StickerPack"]]:
    """
    List the sticker packs available to Nitro subscribers.

    Returns:
        A list of StickerPack objects if found, otherwise returns None

    """
    try:
        packs_data = await self.http.list_nitro_sticker_packs()
        return [StickerPack.from_dict(data, self) for data in packs_data]

    except NotFound:
        return None

fetch_scheduled_event(guild_id, scheduled_event_id, with_user_count=False) async

Fetch a scheduled event by id.

Parameters:

Name Type Description Default
guild_id Snowflake_Type

The ID of the guild to get the scheduled event from

required
scheduled_event_id Snowflake_Type

The ID of the scheduled event to get

required
with_user_count bool

Whether to include the user count in the response

False

Returns:

Type Description
Optional[ScheduledEvent]

The scheduled event if found, otherwise None

Source code in interactions/client/client.py
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
async def fetch_scheduled_event(
    self,
    guild_id: "Snowflake_Type",
    scheduled_event_id: "Snowflake_Type",
    with_user_count: bool = False,
) -> Optional["ScheduledEvent"]:
    """
    Fetch a scheduled event by id.

    Args:
        guild_id: The ID of the guild to get the scheduled event from
        scheduled_event_id: The ID of the scheduled event to get
        with_user_count: Whether to include the user count in the response

    Returns:
        The scheduled event if found, otherwise None

    """
    try:
        scheduled_event_data = await self.http.get_scheduled_event(guild_id, scheduled_event_id, with_user_count)
        return self.cache.place_scheduled_event_data(scheduled_event_data)
    except NotFound:
        return None

fetch_sticker(sticker_id) async

Fetch a sticker by ID.

Parameters:

Name Type Description Default
sticker_id Snowflake_Type

The ID of the sticker.

required

Returns:

Type Description
Optional[Sticker]

A sticker object if found, otherwise None

Source code in interactions/client/client.py
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
async def fetch_sticker(self, sticker_id: "Snowflake_Type") -> Optional[Sticker]:
    """
    Fetch a sticker by ID.

    Args:
        sticker_id: The ID of the sticker.

    Returns:
        A sticker object if found, otherwise None

    """
    try:
        sticker_data = await self.http.get_sticker(sticker_id)
        return Sticker.from_dict(sticker_data, self)
    except NotFound:
        return None

fetch_user(user_id, *, force=False) async

Fetch a user.

Note

This method is an alias for the cache which will either return a cached object, or query discord for the object if its not already cached.

Parameters:

Name Type Description Default
user_id Snowflake_Type

The ID of the user to get

required
force bool

Whether to poll the API regardless of cache

False

Returns:

Type Description
Optional[User]

User Object if found, otherwise None

Source code in interactions/client/client.py
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
async def fetch_user(self, user_id: "Snowflake_Type", *, force: bool = False) -> Optional[User]:
    """
    Fetch a user.

    !!! note
        This method is an alias for the cache which will either return a cached object, or query discord for the object
        if its not already cached.

    Args:
        user_id: The ID of the user to get
        force: Whether to poll the API regardless of cache

    Returns:
        User Object if found, otherwise None

    """
    try:
        return await self.cache.fetch_user(user_id, force=force)
    except NotFound:
        return None

fetch_voice_regions() async

List the voice regions available on Discord.

Returns:

Type Description
List[VoiceRegion]

A list of voice regions.

Source code in interactions/client/client.py
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
async def fetch_voice_regions(self) -> List["VoiceRegion"]:
    """
    List the voice regions available on Discord.

    Returns:
        A list of voice regions.

    """
    regions_data = await self.http.list_voice_regions()
    return VoiceRegion.from_list(regions_data)

get_application_cmd_by_id(cmd_id, *, scope=None)

Get a application command from the internal cache by its ID.

Parameters:

Name Type Description Default
cmd_id Snowflake_Type

The ID of the command

required
scope Snowflake_Type

Optionally specify a scope to search in

None

Returns:

Type Description
Optional[InteractionCommand]

The command, if one with the given ID exists internally, otherwise None

Source code in interactions/client/client.py
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
def get_application_cmd_by_id(
    self, cmd_id: "Snowflake_Type", *, scope: "Snowflake_Type" = None
) -> Optional[InteractionCommand]:
    """
    Get a application command from the internal cache by its ID.

    Args:
        cmd_id: The ID of the command
        scope: Optionally specify a scope to search in

    Returns:
        The command, if one with the given ID exists internally, otherwise None

    """
    cmd_id = to_snowflake(cmd_id)
    scope = to_snowflake(scope) if scope is not None else None

    if scope is not None:
        return next(
            (cmd for cmd in self.interactions_by_scope[scope].values() if cmd.get_cmd_id(scope) == cmd_id), None
        )
    return next(cmd for cmd in self._interaction_lookup.values() if cmd_id in cmd.cmd_id.values())

get_bot_voice_state(guild_id)

Get the bot's voice state for a guild.

Parameters:

Name Type Description Default
guild_id Snowflake_Type

The target guild's id.

required

Returns:

Type Description
Optional[ActiveVoiceState]

The bot's voice state for the guild if connected, otherwise None.

Source code in interactions/client/client.py
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
def get_bot_voice_state(self, guild_id: "Snowflake_Type") -> Optional[ActiveVoiceState]:
    """
    Get the bot's voice state for a guild.

    Args:
        guild_id: The target guild's id.

    Returns:
        The bot's voice state for the guild if connected, otherwise None.

    """
    return self._connection_state.get_voice_state(guild_id)

get_channel(channel_id)

Get a channel.

Note

This method is an alias for the cache which will return a cached object.

Parameters:

Name Type Description Default
channel_id Snowflake_Type

The ID of the channel to get

required

Returns:

Type Description
Optional[TYPE_ALL_CHANNEL]

Channel Object if found, otherwise None

Source code in interactions/client/client.py
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
def get_channel(self, channel_id: "Snowflake_Type") -> Optional["TYPE_ALL_CHANNEL"]:
    """
    Get a channel.

    !!! note
        This method is an alias for the cache which will return a cached object.

    Args:
        channel_id: The ID of the channel to get

    Returns:
        Channel Object if found, otherwise None

    """
    return self.cache.get_channel(channel_id)

get_custom_emoji(emoji_id, guild_id=None)

Get a custom emoji by id.

Parameters:

Name Type Description Default
emoji_id Snowflake_Type

The id of the custom emoji.

required
guild_id Optional[Snowflake_Type]

The id of the guild the emoji belongs to.

None

Returns:

Type Description
Optional[CustomEmoji]

The custom emoji if found, otherwise None.

Source code in interactions/client/client.py
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
def get_custom_emoji(
    self, emoji_id: "Snowflake_Type", guild_id: Optional["Snowflake_Type"] = None
) -> Optional[CustomEmoji]:
    """
    Get a custom emoji by id.

    Args:
        emoji_id: The id of the custom emoji.
        guild_id: The id of the guild the emoji belongs to.

    Returns:
        The custom emoji if found, otherwise None.

    """
    emoji = self.cache.get_emoji(emoji_id)
    if emoji and (not guild_id or emoji._guild_id == to_snowflake(guild_id)):
        return emoji
    return None

get_ext(name)

Get a extension with a name or extension name.

Parameters:

Name Type Description Default
name str

The name of the extension, or the name of it's extension

required

Returns:

Type Description
Extension | None

A extension, if found

Source code in interactions/client/client.py
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
def get_ext(self, name: str) -> Extension | None:
    """
    Get a extension with a name or extension name.

    Args:
        name: The name of the extension, or the name of it's extension

    Returns:
        A extension, if found

    """
    return ext[0] if (ext := self.get_extensions(name)) else None

get_extensions(name)

Get all ext with a name or extension name.

Parameters:

Name Type Description Default
name str

The name of the extension, or the name of it's extension

required

Returns:

Type Description
list[Extension]

List of Extensions

Source code in interactions/client/client.py
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
def get_extensions(self, name: str) -> list[Extension]:
    """
    Get all ext with a name or extension name.

    Args:
        name: The name of the extension, or the name of it's extension

    Returns:
        List of Extensions

    """
    if name not in self.ext.keys():
        return [ext for ext in self.ext.values() if ext.extension_name == name]

    return [self.ext.get(name, None)]

get_guild(guild_id)

Get a guild.

Note

This method is an alias for the cache which will return a cached object.

Parameters:

Name Type Description Default
guild_id Snowflake_Type

The ID of the guild to get

required

Returns:

Type Description
Optional[Guild]

Guild Object if found, otherwise None

Source code in interactions/client/client.py
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
def get_guild(self, guild_id: "Snowflake_Type") -> Optional[Guild]:
    """
    Get a guild.

    !!! note
        This method is an alias for the cache which will return a cached object.

    Args:
        guild_id: The ID of the guild to get

    Returns:
        Guild Object if found, otherwise None

    """
    return self.cache.get_guild(guild_id)

get_member(user_id, guild_id)

Get a member from a guild.

Note

This method is an alias for the cache which will return a cached object.

Parameters:

Name Type Description Default
user_id Snowflake_Type

The ID of the member

required
guild_id Snowflake_Type

The ID of the guild to get the member from

required

Returns:

Type Description
Optional[Member]

Member object if found, otherwise None

Source code in interactions/client/client.py
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
def get_member(self, user_id: "Snowflake_Type", guild_id: "Snowflake_Type") -> Optional[Member]:
    """
    Get a member from a guild.

    !!! note
        This method is an alias for the cache which will return a cached object.

    Args:
        user_id: The ID of the member
        guild_id: The ID of the guild to get the member from

    Returns:
        Member object if found, otherwise None

    """
    return self.cache.get_member(guild_id, user_id)

get_remote_commands(cmd_scope) async

Get the remote commands for a scope.

Parameters:

Name Type Description Default
cmd_scope Snowflake_Type

The scope to get the commands for.

required
Source code in interactions/client/client.py
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
async def get_remote_commands(self, cmd_scope: "Snowflake_Type") -> List[Dict[str, Any]]:
    """
    Get the remote commands for a scope.

    Args:
        cmd_scope: The scope to get the commands for.

    """
    try:
        return await self.http.get_application_commands(self.app.id, cmd_scope)
    except Forbidden:
        self.logger.warning(f"Bot is lacking `application.commands` scope in {cmd_scope}!")
        return []

get_scheduled_event(scheduled_event_id)

Get a scheduled event by id.

Note

This method is an alias for the cache which will return a cached object.

Parameters:

Name Type Description Default
scheduled_event_id Snowflake_Type

The ID of the scheduled event to get

required

Returns:

Type Description
Optional[ScheduledEvent]

The scheduled event if found, otherwise None

Source code in interactions/client/client.py
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
def get_scheduled_event(
    self,
    scheduled_event_id: "Snowflake_Type",
) -> Optional["ScheduledEvent"]:
    """
    Get a scheduled event by id.

    !!! note
        This method is an alias for the cache which will return a cached object.

    Args:
        scheduled_event_id: The ID of the scheduled event to get

    Returns:
        The scheduled event if found, otherwise None

    """
    return self.cache.get_scheduled_event(scheduled_event_id)

get_user(user_id)

Get a user.

Note

This method is an alias for the cache which will return a cached object.

Parameters:

Name Type Description Default
user_id Snowflake_Type

The ID of the user to get

required

Returns:

Type Description
Optional[User]

User Object if found, otherwise None

Source code in interactions/client/client.py
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
def get_user(self, user_id: "Snowflake_Type") -> Optional[User]:
    """
    Get a user.

    !!! note
        This method is an alias for the cache which will return a cached object.

    Args:
        user_id: The ID of the user to get

    Returns:
        User Object if found, otherwise None

    """
    return self.cache.get_user(user_id)

handle_pre_ready_response(data) async

Respond to an interaction that was received before the bot was ready.

Parameters:

Name Type Description Default
data dict

The interaction data

required
Source code in interactions/client/client.py
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
async def handle_pre_ready_response(self, data: dict) -> None:
    """
    Respond to an interaction that was received before the bot was ready.

    Args:
        data: The interaction data

    """
    if data["type"] == InteractionType.AUTOCOMPLETE:
        # we do not want to respond to autocompletes as discord will cache the response,
        # so we just ignore them
        return

    with contextlib.suppress(HTTPException):
        await self.http.post_initial_response(
            {
                "type": CallbackType.CHANNEL_MESSAGE_WITH_SOURCE,
                "data": {
                    "content": f"{self.user.display_name} is starting up. Please try again in a few seconds",
                    "flags": MessageFlags.EPHEMERAL,
                },
            },
            token=data["token"],
            interaction_id=data["id"],
        )

listen(event_name=MISSING)

A decorator to be used in situations that the library can't automatically hook your listeners. Ideally, the standard listen decorator should be used, not this.

Parameters:

Name Type Description Default
event_name Absent[str]

The event name to use, if not the coroutine name

MISSING

Returns:

Type Description
Callable[[AsyncCallable], Listener]

A listener that can be used to hook into the event.

Source code in interactions/client/client.py
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
def listen(self, event_name: Absent[str] = MISSING) -> Callable[[AsyncCallable], Listener]:
    """
    A decorator to be used in situations that the library can't automatically hook your listeners. Ideally, the standard listen decorator should be used, not this.

    Args:
        event_name: The event name to use, if not the coroutine name

    Returns:
        A listener that can be used to hook into the event.

    """

    def wrapper(coro: AsyncCallable) -> Listener:
        listener = Listener.create(event_name)(coro)
        self.add_listener(listener)
        return listener

    return wrapper

load_extension(name, package=None, **load_kwargs)

Load an extension with given arguments.

Parameters:

Name Type Description Default
name str

The name of the extension.

required
package str | None

The package the extension is in

None
**load_kwargs Any

The auto-filled mapping of the load keyword arguments

{}
Source code in interactions/client/client.py
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
def load_extension(
    self,
    name: str,
    package: str | None = None,
    **load_kwargs: Any,
) -> None:
    """
    Load an extension with given arguments.

    Args:
        name: The name of the extension.
        package: The package the extension is in
        **load_kwargs: The auto-filled mapping of the load keyword arguments

    """
    module_name = importlib.util.resolve_name(name, package)
    if module_name in self.__modules:
        raise Exception(f"{module_name} already loaded")

    module = importlib.import_module(module_name, package)
    self.__load_module(module, module_name, **load_kwargs)

load_extensions(*packages, recursive=False, **load_kwargs)

Load multiple extensions at once.

Removes the need of manually looping through the package and loading the extensions.

Parameters:

Name Type Description Default
*packages str

The package(s) where the extensions are located.

()
recursive bool

Whether to load extensions from the subdirectories within the package.

False
Source code in interactions/client/client.py
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
def load_extensions(
    self,
    *packages: str,
    recursive: bool = False,
    **load_kwargs: Any,
) -> None:
    """
    Load multiple extensions at once.

    Removes the need of manually looping through the package
    and loading the extensions.

    Args:
        *packages: The package(s) where the extensions are located.
        recursive: Whether to load extensions from the subdirectories within the package.

    """
    if not packages:
        raise ValueError("You must specify at least one package.")

    for package in packages:
        # If recursive then include subdirectories ('**')
        # otherwise just the package specified by the user.
        pattern = os.path.join(package, "**" if recursive else "", "*.py")

        # Find all files matching the pattern, and convert slashes to dots.
        extensions = [f.replace(os.path.sep, ".").replace(".py", "") for f in glob.glob(pattern, recursive=True)]

        for ext in extensions:
            self.load_extension(ext, **load_kwargs)

login(token=None) async

Login to discord via http.

Note

You will need to run Client.start_gateway() before you start receiving gateway events.

Parameters:

Name Type Description Default
token str

Your bot's token

None
Source code in interactions/client/client.py
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
async def login(self, token: str | None = None) -> None:
    """
    Login to discord via http.

    !!! note
        You will need to run Client.start_gateway() before you start receiving gateway events.

    Args:
        token str: Your bot's token

    """
    if not self.token and not token:
        raise RuntimeError(
            "No token provided - please provide a token in the client constructor or via the login method."
        )
    self.token = (token or self.token).strip()

    # i needed somewhere to put this call,
    # login will always run after initialisation
    # so im gathering commands here
    self._gather_callbacks()

    if any(v for v in constants.CLIENT_FEATURE_FLAGS.values()):
        # list all enabled flags
        enabled_flags = [k for k, v in constants.CLIENT_FEATURE_FLAGS.items() if v]
        self.logger.info(f"Enabled feature flags: {', '.join(enabled_flags)}")

    self.logger.debug("Attempting to login")
    me = await self.http.login(self.token)
    self._user = ClientUser.from_dict(me, self)
    self.cache.place_user_data(me)
    self._app = Application.from_dict(await self.http.get_current_bot_information(), self)
    self._mention_reg = re.compile(rf"^(<@!?{self.user.id}*>\s)")

    if self.app.owner:
        self.owner_ids.add(self.app.owner.id)

    self.dispatch(events.Login())

mention_command(name, scope=0)

Returns a string that would mention the interaction specified.

Parameters:

Name Type Description Default
name str

The name of the interaction.

required
scope int

The scope of the interaction. Defaults to 0, the global scope.

0

Returns:

Name Type Description
str str

The interaction's mention in the specified scope.

Source code in interactions/client/client.py
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
def mention_command(self, name: str, scope: int = 0) -> str:
    """
    Returns a string that would mention the interaction specified.

    Args:
        name: The name of the interaction.
        scope: The scope of the interaction. Defaults to 0, the global scope.

    Returns:
        str: The interaction's mention in the specified scope.

    """
    return self.interactions_by_scope[scope][name].mention(scope)

on_autocomplete_completion(event) async

Called after any autocomplete callback is ran.

By default, it will simply log the autocomplete callback.

Listen to the AutocompleteCompletion event to overwrite this behaviour.

Source code in interactions/client/client.py
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
@Listener.create(is_default_listener=True)
async def on_autocomplete_completion(self, event: events.AutocompleteCompletion) -> None:
    """
    Called *after* any autocomplete callback is ran.

    By default, it will simply log the autocomplete callback.

    Listen to the `AutocompleteCompletion` event to overwrite this behaviour.

    """
    symbol = "$"
    self.logger.info(
        f"Autocomplete Called: {symbol}{event.ctx.invoke_target} with {event.ctx.focussed_option = } |"
        f" {event.ctx.kwargs = }"
    )

on_autocomplete_error(event) async

Catches all errors dispatched by autocompletion options.

By default it will dispatch the Error event.

Listen to the AutocompleteError event to overwrite this behaviour.

Source code in interactions/client/client.py
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
@Listener.create(is_default_listener=True)
async def on_autocomplete_error(self, event: events.AutocompleteError) -> None:
    """
    Catches all errors dispatched by autocompletion options.

    By default it will dispatch the `Error` event.

    Listen to the `AutocompleteError` event to overwrite this behaviour.

    """
    self.dispatch(
        events.Error(
            source=f"Autocomplete Callback for /{event.ctx.invoke_target} - Option: {event.ctx.focussed_option}",
            error=event.error,
            args=event.args,
            kwargs=event.kwargs,
            ctx=event.ctx,
        )
    )

on_command_completion(event) async

Called after any command is ran.

By default, it will simply log the command.

Listen to the CommandCompletion event to overwrite this behaviour.

Source code in interactions/client/client.py
731
732
733
734
735
736
737
738
739
740
741
@Listener.create(is_default_listener=True)
async def on_command_completion(self, event: events.CommandCompletion) -> None:
    """
    Called *after* any command is ran.

    By default, it will simply log the command.

    Listen to the `CommandCompletion` event to overwrite this behaviour.

    """
    self.logger.info(f"Command Called: {event.ctx.invoke_target} with {event.ctx.args = } | {event.ctx.kwargs = }")

on_command_error(event) async

Catches all errors dispatched by commands.

By default it will dispatch the Error event.

Listen to the CommandError event to overwrite this behaviour.

Source code in interactions/client/client.py
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
@Listener.create(is_default_listener=True)
async def on_command_error(self, event: events.CommandError) -> None:
    """
    Catches all errors dispatched by commands.

    By default it will dispatch the `Error` event.

    Listen to the `CommandError` event to overwrite this behaviour.

    """
    self.dispatch(
        events.Error(
            source=f"cmd `/{event.ctx.invoke_target}`",
            error=event.error,
            args=event.args,
            kwargs=event.kwargs,
            ctx=event.ctx,
        )
    )
    with contextlib.suppress(errors.LibraryException):
        if isinstance(event.error, errors.CommandOnCooldown):
            await event.ctx.send(
                embeds=Embed(
                    description=(
                        "This command is on cooldown!\n"
                        f"Please try again in {int(event.error.cooldown.get_cooldown_time())} seconds"
                    ),
                    color=BrandColors.FUCHSIA,
                )
            )
        elif isinstance(event.error, errors.MaxConcurrencyReached):
            await event.ctx.send(
                embeds=Embed(
                    description="This command has reached its maximum concurrent usage!\nPlease try again shortly.",
                    color=BrandColors.FUCHSIA,
                )
            )
        elif isinstance(event.error, errors.CommandCheckFailure):
            await event.ctx.send(
                embeds=Embed(
                    description="You do not have permission to run this command!",
                    color=BrandColors.YELLOW,
                )
            )
        elif self.send_command_tracebacks:
            out = "".join(traceback.format_exception(event.error))
            if self.http.token is not None:
                out = out.replace(self.http.token, "[REDACTED TOKEN]")
            await event.ctx.send(
                embeds=Embed(
                    title=f"Error: {type(event.error).__name__}",
                    color=BrandColors.RED,
                    description=f"```\n{out[:EMBED_MAX_DESC_LENGTH - 8]}```",
                )
            )

on_component_completion(event) async

Called after any component callback is ran.

By default, it will simply log the component use.

Listen to the ComponentCompletion event to overwrite this behaviour.

Source code in interactions/client/client.py
763
764
765
766
767
768
769
770
771
772
773
774
775
776
@Listener.create(is_default_listener=True)
async def on_component_completion(self, event: events.ComponentCompletion) -> None:
    """
    Called *after* any component callback is ran.

    By default, it will simply log the component use.

    Listen to the `ComponentCompletion` event to overwrite this behaviour.

    """
    symbol = "¢"
    self.logger.info(
        f"Component Called: {symbol}{event.ctx.invoke_target} with {event.ctx.args = } | {event.ctx.kwargs = }"
    )

on_component_error(event) async

Catches all errors dispatched by components.

By default it will dispatch the Error event.

Listen to the ComponentError event to overwrite this behaviour.

Source code in interactions/client/client.py
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
@Listener.create(is_default_listener=True)
async def on_component_error(self, event: events.ComponentError) -> None:
    """
    Catches all errors dispatched by components.

    By default it will dispatch the `Error` event.

    Listen to the `ComponentError` event to overwrite this behaviour.

    """
    self.dispatch(
        events.Error(
            source=f"Component Callback for {event.ctx.custom_id}",
            error=event.error,
            args=event.args,
            kwargs=event.kwargs,
            ctx=event.ctx,
        )
    )

on_error(event) async

Catches all errors dispatched by the library.

By default it will format and print them to console.

Listen to the Error event to overwrite this behaviour.

Source code in interactions/client/client.py
663
664
665
666
667
668
669
670
671
672
673
@Listener.create(is_default_listener=True)
async def on_error(self, event: events.Error) -> None:
    """
    Catches all errors dispatched by the library.

    By default it will format and print them to console.

    Listen to the `Error` event to overwrite this behaviour.

    """
    self.default_error_handler(event.source, event.error)

on_modal_completion(event) async

Called after any modal callback is ran.

By default, it will simply log the modal callback.

Listen to the ModalCompletion event to overwrite this behaviour.

Source code in interactions/client/client.py
834
835
836
837
838
839
840
841
842
843
844
@Listener.create(is_default_listener=True)
async def on_modal_completion(self, event: events.ModalCompletion) -> None:
    """
    Called *after* any modal callback is ran.

    By default, it will simply log the modal callback.

    Listen to the `ModalCompletion` event to overwrite this behaviour.

    """
    self.logger.info(f"Modal Called: {event.ctx.custom_id = } with {event.ctx.responses = }")

on_modal_error(event) async

Catches all errors dispatched by modals.

By default it will dispatch the Error event.

Listen to the ModalError event to overwrite this behaviour.

Source code in interactions/client/client.py
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
@Listener.create(is_default_listener=True)
async def on_modal_error(self, event: events.ModalError) -> None:
    """
    Catches all errors dispatched by modals.

    By default it will dispatch the `Error` event.

    Listen to the `ModalError` event to overwrite this behaviour.

    """
    self.dispatch(
        events.Error(
            source=f"Modal Callback for custom_id {event.ctx.custom_id}",
            error=event.error,
            args=event.args,
            kwargs=event.kwargs,
            ctx=event.ctx,
        )
    )

reload_extension(name, package=None, *, load_kwargs=None, unload_kwargs=None)

Helper method to reload an extension. Simply unloads, then loads the extension with given arguments.

Parameters:

Name Type Description Default
name str

The name of the extension.

required
package str | None

The package the extension is in

None
load_kwargs Any

The manually-filled mapping of the load keyword arguments

None
unload_kwargs Any

The manually-filled mapping of the unload keyword arguments

None
Source code in interactions/client/client.py
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
def reload_extension(
    self,
    name: str,
    package: str | None = None,
    *,
    load_kwargs: Any = None,
    unload_kwargs: Any = None,
) -> None:
    """
    Helper method to reload an extension. Simply unloads, then loads the extension with given arguments.

    Args:
        name: The name of the extension.
        package: The package the extension is in
        load_kwargs: The manually-filled mapping of the load keyword arguments
        unload_kwargs: The manually-filled mapping of the unload keyword arguments

    """
    name = importlib.util.resolve_name(name, package)
    module = self.__modules.get(name)

    if module is None:
        self.logger.warning("Attempted to reload extension thats not loaded. Loading extension instead")
        return self.load_extension(name, package)

    backup = module

    try:
        if not load_kwargs:
            load_kwargs = {}
        if not unload_kwargs:
            unload_kwargs = {}

        self.unload_extension(name, package, **unload_kwargs)
        self.load_extension(name, package, **load_kwargs)
    except Exception as e:
        try:
            self.logger.error(f"Error reloading extension {name}: {e} - attempting to revert to previous state")
            try:
                self.unload_extension(name, package, force=True, **unload_kwargs)  # make sure no remnants are left
            except Exception as t:
                self.logger.debug(f"Suppressing error unloading extension {name} during reload revert: {t}")

            sys.modules[name] = backup
            self.__load_module(backup, name, **load_kwargs)
            self.logger.info(f"Reverted extension {name} to previous state ", exc_info=e)
        except Exception as ex:
            sys.modules.pop(name, None)
            raise ex from e

start(token=None)

Start the bot.

If uvloop is installed, it will be used.

info

This is the recommended method to start the bot

Source code in interactions/client/client.py
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
def start(self, token: str | None = None) -> None:
    """
    Start the bot.

    If `uvloop` is installed, it will be used.

    info:
        This is the recommended method to start the bot
    """
    try:
        import uvloop

        has_uvloop = True
    except ImportError:
        has_uvloop = False

    with contextlib.suppress(KeyboardInterrupt):
        if has_uvloop:
            self.logger.info("uvloop is installed, using it")
            if sys.version_info >= (3, 11):
                with asyncio.Runner(loop_factory=uvloop.new_event_loop) as runner:
                    runner.run(self.astart(token))
            else:
                uvloop.install()
                asyncio.run(self.astart(token))
        else:
            asyncio.run(self.astart(token))

start_gateway() async

Starts the gateway connection.

Source code in interactions/client/client.py
1004
1005
1006
1007
1008
1009
async def start_gateway(self) -> None:
    """Starts the gateway connection."""
    try:
        await self._connection_state.start()
    finally:
        await self.stop()

stop() async

Shutdown the bot.

Source code in interactions/client/client.py
1011
1012
1013
1014
1015
1016
async def stop(self) -> None:
    """Shutdown the bot."""
    self.logger.debug("Stopping the bot.")
    self._ready.clear()
    await self.http.close()
    await self._connection_state.stop()

sync_scope(cmd_scope, delete_cmds, local_cmds_json) async

Sync a single scope.

Parameters:

Name Type Description Default
cmd_scope Snowflake_Type

The scope to sync.

required
delete_cmds bool

Whether to delete commands.

required
local_cmds_json Dict[Snowflake_Type, List[Dict[str, Any]]]

The local commands in json format.

required
Source code in interactions/client/client.py
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
async def sync_scope(
    self,
    cmd_scope: "Snowflake_Type",
    delete_cmds: bool,
    local_cmds_json: Dict["Snowflake_Type", List[Dict[str, Any]]],
) -> None:
    """
    Sync a single scope.

    Args:
        cmd_scope: The scope to sync.
        delete_cmds: Whether to delete commands.
        local_cmds_json: The local commands in json format.

    """
    sync_needed_flag = False
    sync_payload = []

    try:
        remote_commands = await self.get_remote_commands(cmd_scope)
        sync_payload, sync_needed_flag = self._build_sync_payload(
            remote_commands, cmd_scope, local_cmds_json, delete_cmds
        )

        if sync_needed_flag or (delete_cmds and len(sync_payload) < len(remote_commands)):
            await self._sync_commands_with_discord(sync_payload, cmd_scope)
        else:
            self.logger.debug(f"{cmd_scope} is already up-to-date with {len(remote_commands)} commands.")

    except Forbidden as e:
        raise InteractionMissingAccess(cmd_scope) from e
    except HTTPException as e:
        self._raise_sync_exception(e, local_cmds_json, cmd_scope)

synchronise_interactions(*, scopes=MISSING, delete_commands=MISSING) async

Synchronise registered interactions with discord.

Parameters:

Name Type Description Default
scopes Sequence[Snowflake_Type]

Optionally specify which scopes are to be synced.

MISSING
delete_commands Absent[bool]

Override the client setting and delete commands.

MISSING

Returns:

Type Description
None

None

Raises:

Type Description
InteractionMissingAccess

If bot is lacking the necessary access.

Exception

If there is an error during the synchronization process.

Source code in interactions/client/client.py
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
async def synchronise_interactions(
    self,
    *,
    scopes: Sequence["Snowflake_Type"] = MISSING,
    delete_commands: Absent[bool] = MISSING,
) -> None:
    """
    Synchronise registered interactions with discord.

    Args:
        scopes: Optionally specify which scopes are to be synced.
        delete_commands: Override the client setting and delete commands.

    Returns:
        None

    Raises:
        InteractionMissingAccess: If bot is lacking the necessary access.
        Exception: If there is an error during the synchronization process.

    """
    s = time.perf_counter()
    _delete_cmds = self.del_unused_app_cmd if delete_commands is MISSING else delete_commands
    await self._cache_interactions()

    cmd_scopes = self._get_sync_scopes(scopes)
    local_cmds_json = application_commands_to_dict(self.interactions_by_scope, self)

    await asyncio.gather(*[self.sync_scope(scope, _delete_cmds, local_cmds_json) for scope in cmd_scopes])

    t = time.perf_counter() - s
    self.logger.debug(f"Sync of {len(cmd_scopes)} scopes took {t} seconds")

unload_extension(name, package=None, force=False, **unload_kwargs)

Unload an extension with given arguments.

Parameters:

Name Type Description Default
name str

The name of the extension.

required
package str | None

The package the extension is in

None
force bool

Whether to force unload the extension - for use in reversions

False
**unload_kwargs Any

The auto-filled mapping of the unload keyword arguments

{}
Source code in interactions/client/client.py
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
def unload_extension(
    self, name: str, package: str | None = None, force: bool = False, **unload_kwargs: Any
) -> None:
    """
    Unload an extension with given arguments.

    Args:
        name: The name of the extension.
        package: The package the extension is in
        force: Whether to force unload the extension - for use in reversions
        **unload_kwargs: The auto-filled mapping of the unload keyword arguments

    """
    name = importlib.util.resolve_name(name, package)
    module = self.__modules.get(name)

    if module is None and not force:
        raise ExtensionNotFound(f"No extension called {name} is loaded")

    with contextlib.suppress(AttributeError):
        teardown = module.teardown
        teardown(**unload_kwargs)

    for ext in self.get_extensions(name):
        ext.drop(**unload_kwargs)

    sys.modules.pop(name, None)
    self.__modules.pop(name, None)

    if self.sync_ext and self._ready.is_set():
        try:
            asyncio.get_running_loop()
        except RuntimeError:
            return
        _ = asyncio.create_task(self.synchronise_interactions())  # noqa: RUF006

update_command_cache(scope, command_name, command_id)

Update the internal cache with a command ID.

Parameters:

Name Type Description Default
scope Snowflake_Type

The scope of the command to update

required
command_name str

The name of the command

required
command_id Snowflake

The ID of the command

required
Source code in interactions/client/client.py
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
def update_command_cache(self, scope: "Snowflake_Type", command_name: str, command_id: "Snowflake") -> None:
    """
    Update the internal cache with a command ID.

    Args:
        scope: The scope of the command to update
        command_name: The name of the command
        command_id: The ID of the command

    """
    if command := self.interactions_by_scope[scope].get(command_name):
        command.cmd_id[scope] = command_id
        self._interaction_lookup[command.resolved_name] = command

wait_for(event, checks=MISSING, timeout=None)

Waits for a WebSocket event to be dispatched.

Parameters:

Name Type Description Default
event Union[str, BaseEvent]

The name of event to wait.

required
checks Absent[Optional[Union[Callable[..., bool], Callable[..., Awaitable[bool]]]]]

A predicate to check what to wait for.

MISSING
timeout Optional[float]

The number of seconds to wait before timing out.

None

Returns:

Type Description
Any

The event object.

Source code in interactions/client/client.py
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
def wait_for(
    self,
    event: Union[str, "BaseEvent"],
    checks: Absent[Optional[Union[Callable[..., bool], Callable[..., Awaitable[bool]]]]] = MISSING,
    timeout: Optional[float] = None,
) -> Any:
    """
    Waits for a WebSocket event to be dispatched.

    Args:
        event: The name of event to wait.
        checks: A predicate to check what to wait for.
        timeout: The number of seconds to wait before timing out.

    Returns:
        The event object.

    """
    event = get_event_name(event)

    if event not in self.waits:
        self.waits[event] = []

    future = asyncio.Future()
    self.waits[event].append(Wait(event, checks, future))

    return asyncio.wait_for(future, timeout)

wait_for_component(messages=None, components=None, check=None, timeout=None) async

Waits for a component to be sent to the bot.

Parameters:

Name Type Description Default
messages Union[Message, int, list]

The message object to check for.

None
components Optional[Union[List[List[Union[BaseComponent, dict]]], List[Union[BaseComponent, dict]], BaseComponent, dict]]

The components to wait for.

None
check Absent[Optional[Union[Callable[..., bool], Callable[..., Awaitable[bool]]]]] | None

A predicate to check what to wait for.

None
timeout Optional[float]

The number of seconds to wait before timing out.

None

Returns:

Type Description
Component

Component that was invoked. Use .ctx to get the ComponentContext.

Raises:

Type Description
asyncio.TimeoutError

if timed out

Source code in interactions/client/client.py
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
async def wait_for_component(
    self,
    messages: Union[Message, int, list] = None,
    components: Optional[
        Union[
            List[List[Union["BaseComponent", dict]]],
            List[Union["BaseComponent", dict]],
            "BaseComponent",
            dict,
        ]
    ] = None,
    check: Absent[Optional[Union[Callable[..., bool], Callable[..., Awaitable[bool]]]]] | None = None,
    timeout: Optional[float] = None,
) -> "events.Component":
    """
    Waits for a component to be sent to the bot.

    Args:
        messages: The message object to check for.
        components: The components to wait for.
        check: A predicate to check what to wait for.
        timeout: The number of seconds to wait before timing out.

    Returns:
        `Component` that was invoked. Use `.ctx` to get the `ComponentContext`.

    Raises:
        asyncio.TimeoutError: if timed out

    """
    if not messages and not components:
        raise ValueError("You must specify messages or components (or both)")

    message_ids = (
        to_snowflake_list(messages) if isinstance(messages, list) else to_snowflake(messages) if messages else None
    )
    custom_ids = list(get_components_ids(components)) if components else None

    # automatically convert improper custom_ids
    if custom_ids and not all(isinstance(x, str) for x in custom_ids):
        custom_ids = [str(i) for i in custom_ids]

    async def _check(event: events.Component) -> bool:
        ctx: ComponentContext = event.ctx
        # if custom_ids is empty or there is a match
        wanted_message = not message_ids or ctx.message.id in (
            [message_ids] if isinstance(message_ids, int) else message_ids
        )
        wanted_component = not custom_ids or ctx.custom_id in custom_ids
        if wanted_message and wanted_component:
            if asyncio.iscoroutinefunction(check):
                return bool(check is None or await check(event))
            return bool(check is None or check(event))
        return False

    return await self.wait_for("component", checks=_check, timeout=timeout)

wait_for_modal(modal, author=None, timeout=None) async

Wait for a modal response.

Parameters:

Name Type Description Default
modal Modal

The modal we're waiting for.

required
author Optional[Snowflake_Type]

The user we're waiting for to reply

None
timeout Optional[float]

A timeout in seconds to stop waiting

None

Returns:

Type Description
ModalContext

The context of the modal response

Raises:

Type Description
asyncio.TimeoutError

if no response is received that satisfies the predicate before timeout seconds have passed

Source code in interactions/client/client.py
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
async def wait_for_modal(
    self,
    modal: "Modal",
    author: Optional["Snowflake_Type"] = None,
    timeout: Optional[float] = None,
) -> "ModalContext":
    """
    Wait for a modal response.

    Args:
        modal: The modal we're waiting for.
        author: The user we're waiting for to reply
        timeout: A timeout in seconds to stop waiting

    Returns:
        The context of the modal response

    Raises:
        asyncio.TimeoutError: if no response is received that satisfies the predicate before timeout seconds have passed

    """
    author = to_snowflake(author) if author else None

    def predicate(event) -> bool:
        if modal.custom_id != event.ctx.custom_id:
            return False
        return author == to_snowflake(event.ctx.author) if author else True

    resp = await self.wait_for("modal_completion", predicate, timeout)
    return resp.ctx

wait_until_ready() async

Waits for the client to become ready.

Source code in interactions/client/client.py
1060
1061
1062
async def wait_until_ready(self) -> None:
    """Waits for the client to become ready."""
    await self._ready.wait()