因此,我试图使我的机器人使用discord.py保持欢迎状态并删除消息。
import discord
from discord.ext import commands
import random
client = commands.Bot(command_prefix = '.')
@client.event
async def on_member_join(ctx, *, member):
channel = member.server.get_channel("channel id")
fmt = 'Welcome to the {1.name} Discord server, {0.mention}'
await ctx.send_message(channel, fmt.format(member, member.server))
@client.event
async def on_member_remove(ctx, *, member):
channel = member.server.get_channel("channel id")
fmt = '{0.mention} has left/been kicked from the server.'
await ctx.send_message(channel, fmt.format(member, member.server))
client.run('client id')
错误
File "C:\python\lib\site-packages\discord\client.py", line 312, in _run_event
await coro(*args, **kwargs)
TypeError: on_member_join() missing 1 required keyword-only argument: 'member'
出现。
我不确定为什么它不起作用。我对此的经验很少,所以我不确定自己做错了什么。谁能告诉我我在想什么?
答案 0 :(得分:1)
@client.event
async def on_member_join(member):
await client.get_channel(idchannel).send(f"{member.name} has joined")
@client.event
async def on_member_remove(member):
await client.get_channel(idchannel).send(f"{member.name} has left")
一旦发生事件,您将无法获得ctx,因为它不是命令,必须由谁编写。是活动
答案 1 :(得分:1)
const [search, setSearch] = useState('');
<Layout search={search} setSearch={setSearch}>
<Route exact path='/' search={search} component={Products} />
</Layout>
还请记住,idchannel是int,而不是字符串