我正试图在python中制作我的第一个discord机器人。它运行得很好,直到我想添加功能,当机器人在特定频道迎接新成员时。
这是我的代码:
import discord
from discord.ext import commands
from discord.ext.commands import has_permissions
intents = discord.Intents.all()
client = commands.Bot(command_prefix='.',intents=intents)
@client.event
async def on_ready():
await client.change_presence(activity=discord.Game(name="chess with your mum"))
print("Bot is ready")
@client.event
async def on_member_join(member):
channel = client.get.channel(828249420784205824)
await channel.send(f'{member} dolaczyl do serwera!') #in english: "joined the server!"
@client.event
async def on_member_leave(member):
channel = client.get.channel(828249420784205824)
await channel.send(f'{member} opuscil serwer!') #in english: "leaved the server!"
@client.command()
@has_permissions(ban_members = True)
async def ban(ctx, member : discord.Member, *, reason=None):
await member.ban(reason=reason)
await ctx.send(f'Uzytkownik {member} dostal bana!') #in english: "got banned"
@client.command()
@has_permissions(kick_members = True)
async def kick(ctx, member : discord.Member, *, reason=None):
await member.kick(reason=reason)
await ctx.send(f'Uzytkownik {member} zostal wyrzucony!') #in english: "got kicked"
client.run('TOKEN')
错误:
2022-12-17 20:21:24 ERROR discord.client Ignoring exception in on_member_join
Traceback (most recent call last):
File "/home/runner/Bot/venv/lib/python3.8/site-packages/discord/client.py", line 409, in _run_event
await coro(*args, **kwargs)
File "main.py", line 16, in on_member_join
channel = client.get.channel(828249420784205824)
AttributeError: 'Bot' object has no attribute 'get'
如果有人能帮助我,我将非常高兴。谢谢
我认为您正在寻找client.get_channel方法,而不是不存在的client.get.channel
。