理论上,我知道如何通过定义命令更改昵称。这一次,我只想在我的服务器中创建一个特殊的通道,它可以将所有文本转换为用户昵称,而不需要输入任何命令/前缀。(并删除该案文)。我试了几种方法,但都失败了。这方面的一些例子:
@bot.event
async def on_message(ctx):
if ctx.channel.id != 853665391272263691:
return
text = message.content.lower()
else:
ctx.author.edit(nick={text})抛出的错误:
File "main.py", line 23
else:
^
SyntaxError: invalid syntax第二种方法:
@bot.event
async def bot.on_message(msg):
if msg.channel.id == 853665391272263691:
await msg.author.edit(nick=f'{msg.author.name}1')
else:
return它抛出了许多不同的错误,比如msg undefined或者只是没有权限(当这个机器人是管理员的时候)。怎么做?)
经过几次尝试,我试过了。我想我离得更近了,但它还是没用的.
@bot.event
async def on_message(ctx):
if ctx.channel.id != 853665391272263691:
return
# if ctx.channel.id == 853665391272263691 will continue
text = str(ctx.content).lower()
ctx.author.edit(nick=text)这会引发错误:
main.py:24: RuntimeWarning: coroutine 'Member.edit' was never awaited
ctx.author.edit(nick=text)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback进口图书馆:
import os
from datetime import datetime
import discord
from discord import Embed, Color
from discord.ext import commands
from keep_alive import keep_alive
from discord_slash import SlashCommand没办法让这个魅力发挥作用还是.?
全源代码这里
发布于 2021-06-28 22:20:16
试一试:
@bot.event
async def on_message(ctx):
if ctx.channel.id != 853665391272263691:
return
# if ctx.channel.id == 853665391272263691 will continue
text = ctx.message.content # before: ctx.message.content.lower()
await ctx.author.edit(nick=text)编辑过的
https://stackoverflow.com/questions/68170157
复制相似问题